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 注解。
  • 相关阅读:
    switch语句
    switch语句
    if语句三种格式
    dowhile语句
    if语句三种格式
    if语句配对
    ansible
    linux系统中网站服务程序(web服务/httpd服务)
    ansible
    ansible
  • 原文地址:https://www.cnblogs.com/wangdapeng/p/5053483.html
Copyright © 2011-2022 走看看