zoukankan      html  css  js  c++  java
  • context:annotation-config

        <!-- enable processing of annotations such as @Autowired and @Configuration -->
        <context:annotation-config/>

    Activates various annotations to be detected in bean classes: Spring's @Required and @Autowired, as well as JSR 250's @PostConstruct, @PreDestroy and @Resource (if available), JAX-WS's @WebServiceRef (if available), EJB3's @EJB (if available), and JPA's @PersistenceContext and @PersistenceUnit (if available). Alternatively, you may choose to activate the individual BeanPostProcessors for those annotations. Note: This tag does not activate processing of Spring's @Transactional or EJB3's @TransactionAttribute annotation. Consider the use of the <tx:annotation-driven> tag for that purpose. See javadoc for org.springframework.context.annotation.AnnotationConfigApplicationContext for information on code-based alternatives to bootstrapping annotation-driven support. from XML.

    • @Required
    • @Autowired
    • @PostConstruct
    • @PreDestroy
    • @Resource
    • @WebServiceRef
    • @EJB
    • @PersistenceContext
    • @PersistenceUnit

    JSR  Java Specification Request

    EJB Enterprise JavaBeans

    用途

    激活注解类

    注解类

    @AutoWired

    1. 使用spring的bean
    2. required = true 是指必须在bean文件中存在
    3. bean文件中的bean通过property为bean设值,java文件中必须存在setter
    4. bean文件中的bean通过构造参数为bean设置时,不需要setter
    5. 获取spring的某bean时,如果发现这个类中有AutoWired 则会在spring bean 资源中查找并注入,不需要setter

    总结:

    1. spring bean 相当于资源库,里面的资源存在依赖关系,依赖关系在java类中通过@AutoWired声明,强依赖的required=true ,弱依赖的required=false 。
    2. spring bean 要达到的效果就是,依赖的反转控制 。 不需要new 不需要setter。

    属性必须注入

    @Required

      @Required
        public void setName(String name) {
            this.name = name;
        }
      <bean class="cn.zno.Person">
            <property name="name" value="xiaoming"></property>
        </bean>
  • 相关阅读:
    cesium 学习(七) HeadingPitchRoll
    cesium 学习(六) 坐标转换
    cesium 学习(五) 加载场景模型
    Cesium 学习(一)环境搭建
    Cesium 学习(二)所支持的模型数据类型,以及转换
    cesium 学习(四) Hello World
    Cesium 学习(三)各种资源链接
    【Windows编程】系列第十一篇:多文档界面框架
    【Windows编程】系列第十篇:文本插入符
    【Windows编程】系列第八篇:通用对话框
  • 原文地址:https://www.cnblogs.com/zno2/p/4689681.html
Copyright © 2011-2022 走看看