天质软件

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Spring配置中的<context:annotation-config/>

转载:http://www.cnblogs.com/-bumblebee-/archive/2012/03/23/2413366.html#commentform

被公司安排到别的项目了,也没时间学Android了,好多天都没写Blog了。。

今天在配置applicationContext.xml时看到个东西:

<context:annotation-config/>

他的作用是隐式地向 Spring 容器注册

AutowiredAnnotationBeanPostProcessor、

CommonAnnotationBeanPostProcessor、

PersistenceAnnotationBeanPostProcessor、

RequiredAnnotationBeanPostProcessor 

这 4 个BeanPostProcessor。

例如:

如果想使用@ Resource 、@ PostConstruct、@ PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor。

如果想使用@PersistenceContext注解,就必须声明PersistenceAnnotationBeanPostProcessor的Bean。

如果你想使用@Autowired注解,那么就必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。传统声明方式如下:

<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor "/> 

如果想使用 @Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。同样,传统的声明方式如下:

<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/> 

 

 

记得,使用注解一般都会配置扫描包路径选项

<context:component-scan base-package=”XX.XX”/
posted on 2012-11-27 12:45  天质软件  阅读(109)  评论(0编辑  收藏  举报