&

单词:

        annotation  注释

        [ænə'teɪʃ(ə)n]

        component 组件


正式开始讲解 用(1)代替 与 用(2)代替:

            (1)用来激活已经在spring容器里注册过的bean上面的注释(即在application.xml中配置的 标签中的类)。

       例如: 在spring容器中注册testA和testB两个类,

                                                                                           ,

       然后使用注释@Autowired在testA类中注入testB类, @Autowired

                                                                                                     private testB bbbb;

            (2)不仅可以激活已经在spring容器中注册过的bean上面的注释。还可以注册package指定的包中的注释类(

       @component, @controler, @service...注释的类会被自动注册到spring容器中)。

       例如:在spring容器中不配置,而是配置

       在testA类和testB类的上面加上注释@component或@service或@controler。


如果(1)和(2)同时存在,那么spring容器会忽略(1),因为(2)的功能包含(1),保证不重复想spring注册相同类。

你可能感兴趣的:(Spring,MVC,spring,co)