`
反求诸己
  • 浏览: 535372 次
  • 性别: Icon_minigender_1
  • 来自: 湖南娄底
社区版块
存档分类
最新评论

精通Spring 之 注解【<context:annotation-config/>】

 
阅读更多

5.6.6  借用<context:annotation-config/>元素

在前面内容中,为启用@Required和@Autowired注解,开发者需要在XML配置文件中分别定义RequiredAnnotationBeanPostProcessor和AutowiredAnnotationBeanPostProcessor对象。Spring支持大量的注解集合,比如@PostConstruct、@PreDestroy、@Resource、@WebServiceRef、@EJB、@PersistenceContext、@PersistenceUnit等。

为简化配置文件的编写,Spring特意内置了<context:annotation-config/>元素,使用示例如下。

  1. <context:annotation-config/> 

一旦提供<context:annotation-config/>元素,开发者就再也不用为各注解提供相应的支持对象了,比如RequiredAnnotationBeanPostProcessor。【注解:<context:annotationconfig/> 将隐式地向 Spring 容器注册 AutowiredAnnotationBeanPostProcessor CommonAnnotationBeanPostProcessor PersistenceAnnotationBeanPostProcessor 以及 equiredAnnotationBeanPostProcessor 这 4 个 BeanPostProcessor。】

与此同时,开发者也要意识到这一元素的缺陷,比如它不能够自定义RequiredAnnotationBeanPostProcessor的行为。

分享到:
评论

相关推荐

    Spring3中配置DBCP,C3P0,Proxool,Bonecp数据源

    &lt;context:annotation-config /&gt; &lt;context:component-scan base-package="com.mvc" /&gt; &lt;mvc:annotation-driven /&gt; &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt; &lt;mvc:default-servlet-...

    SpringMVC+Hibernate全注解整合

    &lt;context:annotation-config/&gt; &lt;context:component-scan base-package="com.org.*" /&gt; &lt;bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property...

    spring3.2+strut2+hibernate4

    &lt;context:annotation-config /&gt; &lt;!-- &lt;bean id="sessionFactory"--&gt; &lt;!-- class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;--&gt; &lt;!-- &lt;property name="configLocation"--&gt; &lt;!-- value=...

    Spring AOP配置源码

    &lt;/beans&gt;&lt;context:annotation-config/&gt; &lt;context:component-scan base-package="com.spring.*"/&gt; 两行为开启spring的注解配置 &lt;aop:aspect id="aspect" ref="logIntercepter"&gt; 引入具体的AOP操作类 &lt;aop:pointcut ...

    SpringMVC-SSH全注解

    &lt;context:annotation-config/&gt; &lt;!-- 扫描包 --&gt; &lt;context:component-scan base-package="com.org.core"/&gt; &lt;bean id="jspViewResolver" class="org.springframework.web.servlet.view....

    OA项目SSH整合框架

    &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/...

    spring_MVC源码

    10. &lt;context:annotation-config /&gt; 11. &lt;!-- 把标记了@Controller注解的类转换为bean --&gt; 12. &lt;context:component-scan base-package="com.mvc.controller" /&gt; 13. &lt;!-- 启动Spring MVC的注解功能,...

    客户关系管理系统框架搭建(二)

    &lt;tx:annotation-driven transaction-manager="txManager"/&gt; * 创建dao层共同的接口,放置在cn.itcast.crm.dao下 public interface ICommonDao&lt;T&gt; { public void save(T entity); } * ...

    java微信公众号MVC开发框架

    &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;servlet&gt; &lt;servlet-name&gt;weixin&lt;/servlet-name&gt; &lt;servlet-class&gt;...

    springmybatis

    DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"&gt; &lt;configuration&gt; &lt;typeAliases&gt; &lt;typeAlias alias="User" type=...

Global site tag (gtag.js) - Google Analytics