In one spring context I found that some bean references contains & before bean name. I wonder what & in the begin of spring name means.
They are references to FactoryBeans (i.e. to the factories themselves, as opposed to the objects that the factories produce). From the Spring documentation
When you need to ask a container for an actual
FactoryBeaninstance itself, not the bean it produces, you preface the bean id with the ampersand symbol&(without quotes) when calling thegetBean()method of theApplicationContext. So for a givenFactoryBeanwith an id of myBean, invokinggetBean("myBean")on the container returns the product of theFactoryBean, and invokinggetBean("&myBean")returns theFactoryBeaninstance itself.
Ampersands in XML need to be escaped as & entity references, so if you wanted to declare a property value in XML which is a reference to a FactoryBean you'd need
<property name="someProperty" ref="&myBean" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With