spring <context:component-scan/>与<context:annotation-config/>
2014-07-27 13:42
489 查看
<context:annotation-config/>可以直接注册
AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、PersistenceAnnotationBeanPostProcessor、
RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。
使 用@Autowired注解,那么就必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor "/>
使 用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor。
使 用 @PersistenceContext注解,就必须声明PersistenceAnnotationBeanPostProcessor。
使 用 @Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
<context:component-scan/> 配置项不但启用了对类包进行扫描以实施注释驱动 Bean 定义的功能,同时还启用了注释驱动自动注入的功能(即还隐式地在内部注测了AutowiredAnnotationBeanPostProcessor 和 CommonAnnotationBeanPostProcessor。
当使用 <context:component-scan/> 后,若只用@Autowired@ Resource 、@ PostConstruct、@ PreDestroy,则可不注册<context:annotation-config/>
AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、PersistenceAnnotationBeanPostProcessor、
RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。
使 用@Autowired注解,那么就必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor "/>
使 用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor。
使 用 @PersistenceContext注解,就必须声明PersistenceAnnotationBeanPostProcessor。
使 用 @Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
<context:component-scan/> 配置项不但启用了对类包进行扫描以实施注释驱动 Bean 定义的功能,同时还启用了注释驱动自动注入的功能(即还隐式地在内部注测了AutowiredAnnotationBeanPostProcessor 和 CommonAnnotationBeanPostProcessor。
当使用 <context:component-scan/> 后,若只用@Autowired@ Resource 、@ PostConstruct、@ PreDestroy,则可不注册<context:annotation-config/>
相关文章推荐
- Spring配置文件详解一:<:<context:annotation-config/>与<context:component-scan base-package="com.xx
- Spring注解之xml配置中的<context:component-scan />和<context:annotation-config/>
- Spring <context:annotation-config/> <context:component-scan/>与<mvc:annotation-driven />
- Spring配置文件详解一:<context:annotation-config/>与<context:component-scan base-package="com.x
- Spring配置文件详解一:<context:annotation-config/>与<context:component-scan base-package="com.xx
- Spring <context:component-scan base-package="">和<context:annotation-config>
- Spring配置文件详解:<context:annotation-config/>和<context:component-scan base-package=""/>和<mvc:annotation-driven />
- spring源码分析之<context:component-scan/>vs<annotation-config/>
- <mvc:annotation-driven/> <context:annotation-config/> <context:component-scan>
- spring 中<context:annotation-config />和<context:component-scan base-package="com.*" >
- <context:annotation-config/>,<context:component-scan/>,<mvc:annotation-driven/>区分
- Spring:<context:annotation-config/>与<context:component-scan base-package="com.xx />
- spring mvc <mvc:annotation-driven/> 和<context:component-scan base-package=""/>解释
- Spring 开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别
- Spring 开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别
- 关于使用注解的Spring配置文件的配置<context:annotation-config/>&&<context:component-scan base-package=”XX.XX”/>
- Spring <context:component-scan base-package=""/> 与 <context:annotation-config/>的区别
- Spring <context:annotation-config/> 、<context:component-scan>解说
- Spring配置文件详解:<context:annotation-config/>和<context:component-scan base-package=""/>和<mvc:annotati...
- Spring <context:annotation-config/> 和 <context:component-scan>