This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

The queueSource is looking at an ActiveMQConnectionFactory defined in JNDI. Basically what I really need is for the "com.acme.Foo" object to have the broker URL of the connection factory. However, javax.jms.ConnectionFactory interface doesn't provide access to it and I didn't want to change my code to use an ActiveMQConnectionFactory (i.e. trying to stick to using interfaces), but I need the broker URL.

So I thought I'd pass in the "queueSource" of type JndiObjectFactoryBean so I could get the info I needed without directly referencing ActiveMQ in my code....but I get an error because Spring is trying to pass my constructor the ActiveMQConnectionFactory instead of the JndiObjectFactoryBean.

So I thought I'd pass in the "queueSource" of type JndiObjectFactoryBean so I could get the info I needed without directly referencing ActiveMQ in my code....but I get an error because Spring is trying to pass my constructor the ActiveMQConnectionFactory instead of the JndiObjectFactoryBean.

...
Finally, there is sometimes a need to ask a container for an actual FactoryBean instance itself, not the bean it produces. This may be achieved by prepending the bean id with '&' (sans quotes) when calling the getBean method of the BeanFactory (including ApplicationContext). So for a given FactoryBean with an id of myBean, invoking getBean("myBean") on the container will return the product of the FactoryBean, but invoking getBean("&myBean") will return the FactoryBean instance itself.

However, I see couple of drawbacks at your approach:

Your code is coupled to the Spring if it works in terms of JndiFactoryBean class;

Comment

You're not allowed to use '&' symbol directly at the xml. It should looks like the following:

HTML Code:

<constructor-arg ref="&amp;queueSource" />

Anyway, it's bad to inject JndiObjectFactoryBean object only for the purpose of the property retrieval. It's much more better to inject the property itself to the bean that needs it. You can guarantee that factory bean and interested bean use the same property value if it is defined at external properties file and is injected to them via PPC.