关于spring中<context:annotation-config/>配置

    在spring的配置文件中,如果我们一个一个地配置bean会非常麻烦,因此我们可以使用注解的方式

    使用@Autowired注解,必须事先在Spring容器中声明AutowiredAnnotationBeanPostProcessor的Bean:

    使用 @Required注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean

     类似地,使用@Resource、@PostConstruct、@PreDestroy等注解就必须声明 CommonAnnotationBeanPostProcessor;
    使用@PersistenceContext注解,就必须声明 PersistenceAnnotationBeanPostProcessor的Bean。
  

  这样配置未免繁琐,难看..因此Spring为解决这个问题,提供了和很方便一次性解决方案
    就是在spring的配置文件中国配置

    <context:annotation-config></context:annotation-config>

    另外,我们在配置注解的时候也会配置包扫面,自动扫面配置的包下面的javabean,实现自动注入

    <context:component-scan base-package="com.crm"></context:component-scan>

    另外使用context命名空间必须在beans中声明context命名空间

    

  


原文地址:https://www.cnblogs.com/ou134568/p/6916832.html