So for some reason half our project’s beans are marked with @Component and injected into other objects marked @Component with the @Autowired annotation, while the other half is wired up explicitly with appliciationContext.xml bean declarations and properties with ref beans values.
Question is, in those xml bean declarations, can I inject one of the objects marked @Component? If so, what will its bean reference name be?
For example;
Some classes are annotated like so;
@Component
public class BeanAImpl{ ... }
Then in applicationContext.xml other classes are wired explicitly as they are not annotated;
<bean id="beanB" class="com.myapp.BeanBImpl"></bean>
Can I inject both ‘kinds’ of beans in applicationContext.xml?
<bean id="beanUser" class="com.myapp.BeanUserImpl">
<property name="beanA">HOW_TO_GET_REF_TO_BEANA?</property>
<property name="beanB"><ref bean="beanB"/></property>
</bean>
Default name for
@Componentof typeBeanAImplisbeanAImpl, you can use it in XML as you do with manually declared beans (also note that<property>allows shorter syntax):Alternatively, you can explicitly set a name as
@Component("beanA").