Difference between and

前端 未结 15 2407
再見小時候
再見小時候 2020-11-22 04:44

I\'m learning Spring 3 and I don\'t seem to grasp the functionality behind and .

15条回答
  •  囚心锁ツ
    2020-11-22 05:35

    
    

    Only resolves the @Autowired and @Qualifer annotations, that's all, it about the Dependency Injection, There are other annotations that do the same job, I think how @Inject, but all about to resolve DI through annotations.

    Be aware, even when you have declared the element, you must declare your class how a Bean anyway, remember we have three available options

    • XML:
    • @Annotations: @Component, @Service, @Repository, @Controller
    • JavaConfig: @Configuration, @Bean

    Now with

    
    

    It does two things:

    • It scans all the classes annotated with @Component, @Service, @Repository, @Controller and @Configuration and create a Bean
    • It does the same job how does.

    Therefore if you declare , is not necessary anymore declare too.

    Thats all

    A common scenario was for example declare only a bean through XML and resolve the DI through annotations, for example

    
    
    
    
    

    We have only declared the beans, nothing about and , the DI is configured in their own classes through @Autowired. It means the Services use @Autowired for their Repositories components and the Repositories use @Autowired for the JdbcTemplate, DataSource etc..components

提交回复
热议问题