If we anotate a class reference with @Autowired then is it mandatory to define a bean of that class reference in the spring configuration xml
Hauke Ingmar Schmidt
Rancher
Joined: Nov 18, 2008
Posts: 371
posted
0
No. A bean that fits must be in the application context, by whatever method.
If you are using the @Autowired annotation you certainly don't want to use XML files for configuration?
bagaria kushal
Greenhorn
Joined: Mar 29, 2011
Posts: 19
posted
0
My question is that if i use @autowired annotaion for a object reference then do i need to make an entry for bean of that reference in spring xml for eg
Shasi Mitra wrote:You can give this <context:component-scan base-package="org.example"/> . Now, all your beans in the package will be instantiated.
As long as you are using @Component or one of its stereotype annotations.
@Component replaces the need for <bean> tags
@Autowired replaces the need for <property> or <constructor-arg> tags.
Usually you use both, but you don't have to.
You can use just @Autowired without any @Component, then in that scenario you will need <bean> tags for all the classes. Also, with this scenario you don't use component-scan, or need it, you use <context:annotation-config> instead.