关于spring中配置


    在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命名空间

    

  


					


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM