zoukankan      html  css  js  c++  java
  • 从 Spring 2.5 开始就可以使用注解来配置依赖注入,而不是采用 XML 来描述一个 bean。

    1、在 XML 注入之前进行注解注入,因此后者可以被前者重写。

    2、在默认情况下注解在 Spring 容器中不打开,需要配置启动。

    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
       <context:annotation-config/>
    
    </beans>

    3、注解的位置有属性、方法和构造函数。

    • @Required 注解应用于 bean 属性的 setter 方法。
    • @Autowired 注解可以应用到 bean 属性的 setter 方法,非 setter 方法,构造函数和属性。
    • @Autowired 和 @Qualifier 注解通过指定确切的bean,可以用来放置混乱。
    • Spring 支持 JSR-250 的基础的注解,其中包括了 @Resource,@PostConstruct 和 @PreDestroy 注解。
  • 相关阅读:
    ubuntu播放器
    第一次装ubuntu 没root密码时
    web服务器记录
    socket udp编程步骤
    nfs服务器配置
    带线程函数编译条件
    linux使用一个刚编译驱动方法
    tiny6410_led驱动Makefile
    java-设计模式-外观模式
    java-实现一个简单的java Web容器
  • 原文地址:https://www.cnblogs.com/wangdapeng/p/5053483.html
Copyright © 2011-2022 走看看