zoukankan      html  css  js  c++  java
  • Spring 基于注解的配置 简介

    基于注解的配置

    从 Spring 2.5 开始就可以使用注解来配置依赖注入。而不是采用 XML 来描述一个 bean 连线,你可以使用相关类,方法或字段声明的注解,将 bean 配置移动到组件类本身。

    在 XML 注入之前进行注解注入,因此后者的配置将通过两种方式的属性连线被前者重写。

    注解连线在默认情况下在 Spring 容器中不打开。因此,在可以使用基于注解的连线之前,我们将需要在我们的 Spring 配置文件中启用它。

    所以如果你想在 Spring 应用程序中使用的任何注解,可以考虑到下面的配置文件。

    <?xml version="1.0" encoding="UTF-8"?>
    
    <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/>
       <!-- bean definitions go here -->
    
    </beans>
    

    注解的英文单词是:annotation

    一旦 被配置后,你就可以开始注解你的代码,表明 Spring 应该自动连接值到属性,方法和构造函数。

    以下,是几个重要的注解:

    每天学习一点点,每天进步一点点。

  • 相关阅读:
    面试汇总
    Windows 环境下的 protoc 安装(转)
    Hbase 元数据一致性检查(转)
    Slow ReadProcessor&amp;Error Slow BlockReceiver错误日志分析(转)
    Hbase CMS GC 调优。
    [技术]排查线上问题
    crontab 误删恢复
    Hbase balancer RSgroup shell 脚本
    Hbase运维手册(1)
    Presto JVM.config
  • 原文地址:https://www.cnblogs.com/youcoding/p/12782114.html
Copyright © 2011-2022 走看看