Spring @ Automated annotation and context Component Scanning and @autowired annotation objects

I am new to spring.

I figured out the @Autowired annotation and for using it. i found out that we have to use 1) context: annotation-config or 2) AutowiredAnnotationBeanPostProcessor . But when I saw the sample project I didn't find anything, so be sure to use the above things.


I think the @Autowired annotation will create objects when our web.xml is deployed to the server, because in a standalone application when I tested, we use public static void main (String [] args) to call the bean class. But in the web project we don't have anything like that, so when we deploy our web.xml to the server or application.xml that contains the spring configuration objects will be created.

I understand my understanding in the above two fantasies.

Please help me.

+3


source to share


1 answer


When using xml file, you need to add PostProcessor Bean for corresponding dependency. You can skip this if you use

 <context:annotation-config/>

      

This would mean that you don't need to add any PostProcessors annotations. This will include all of them.

Second, when you use Autowire annotation, you do automatic wiring by type. You are telling spring to set the value of this field during initialization.



Usually you need to do what in the main application

  • Get applicationContext.
  • Using ApplicationContext get the required bit from XML.
  • Install the Bean to your class of service.

You can skip these steps by implementing an Autwiring Bean in your service class. Let me know if you understand this.

+1


source







All Articles