@Configuration

用于定义配置类,可替换XML配置文件,被注解的类内部包含一个或多个@Bean注解方法。可以被AnnotationConfigApplicationContext或者AnnotationConfigWebApplicationContext 进行扫描。用于构建bean定义以及初始化Spring容器。

ConditionalOnProperty注解

@ConditionalOnProperty(
prefix = "spring.redis",
name = {"enabled"},
havingValue = "true",
matchIfMissing = true
)

其中:

  prefix   是指配置文件中application.properties配置的前缀

  name    属性是从配置文件中读取的属性值

  havingValue 配置读取的属性值跟havingValue做比较,如果一样则返回true 否则返回false

        且,如果返回false那这个confications就不生效,返回true,那这个confication 就生效

  matchIfMissing   默认情况下matchIfMissing为false,也就是说如果未进行属性配置,则自动配置不生效。如果matchIfMissing为true,则表示如果没有对应的属性配置,则自动配置默认生效。

@EnableConfigurationProperties 注解

使使用 @ConfigurationProperties 注解的类生效。

如果一个配置类只配置@ConfigurationProperties注解,而没有使用@Component,那么在IOC容器中是
获取不到properties 配置文件转化的bean。说白了 @EnableConfigurationProperties 相当于把
使用 @ConfigurationProperties 的类进行了一次注入。 当@EnableConfigurationProperties注解应用到你的@Configuration时, 任何
被@ConfigurationProperties注解的beans将自动被Environment属性配置。
这种风格的配置特别适合与SpringApplication的外部YAML配置进行配合使用。

@ConfigurationProperties

使用@ConfigurationProperties方式可以进行配置文件与实体字段的自动映射,但需要字段必须提供set方
法才可以,而使用@Value注解修饰的字段不需要提供set方法

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@Component
@ConfigurationProperties(prefix = "owner.somthing")
public class ControllerTest {
private String name;
private int age; @RequestMapping("/owner")
@ResponseBody
public String onwner(){
return name+age;
}
public void setName(String name) {
this.name = name;
} public void setAge(int age) {
this.age = age;
} @Override
public String toString() {
return "ControllerTest{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}

@Autowired注解

可以对类成员变量、方法及构造函数进行标注,让 spring 完成 bean 自动装配的工作。

required属性值可以为true( 默认值)和false。如果为true的话,没有匹配的类则抛出异常;
如果为false,则表示不是强制必须能够找到相应的类,无论是否注入成功,都不会抛错。

原理解析“

注解解析器:AutowiredAnnotationBeanPostProcessorSpring容器启动时,AutowiredAnnotationBeanPostProcessor被注册到容器;

扫描代码,如果带有@Autowired注解,则将依赖注入信息封装到InjectionMetadata中(见扫描过程);
创建bean时(实例化对象和初始化),会调用各种BeanPostProcessor对bean初始化,AutowiredAnnotationBeanPostProcessor负责将相关的依赖注入进来

@Resource

作用相当于@Autowired,只不过@Autowired按byType自动注入,而@Resource默认按 byName自动注入

name属性解析为bean的名字,而type属性则解析为bean的类型。所以如果使用name属性,则使用byName的自动注入策略,
而使用type属性时则使用byType自动注入策略。
如果既不指定name也不指定type属性,这时将通过反射机制使用byName自动注入策略。

@SuppressWarnings 注解

告诉编译器忽略指定的警告,不用在编译完成后出现警告信息。

value -将由编译器在注释的元素中取消显示的警告集
@SuppressWarnings("unchecked")
  • 请注意,给定元素中抑制的一组警告是所有包含元素中抑制的警告的超集。 例如,如果您注释一个类来抑制一个警告并注释方法来抑制另一个警告,则两个警告将在该方法中被抑制。

value可能遇到的关键字:

关键字 用途
all to suppress all warnings
boxing  to suppress warnings relative to boxing/unboxing operations
cast to suppress warnings relative to cast operations
dep-ann to suppress warnings relative to deprecated annotation
deprecation to suppress warnings relative to deprecation
fallthrough  to suppress warnings relative to missing breaks in switch statements
finally  to suppress warnings relative to finally block that don’t return
hiding to suppress warnings relative to locals that hide variable
incomplete-switch  to suppress warnings relative to missing entries in a switch statement (enum case)
nls  to suppress warnings relative to non-nls string literals
null to suppress warnings relative to null analysis
rawtypes to suppress warnings relative to un-specific types when using generics on class params
restriction to suppress warnings relative to usage of discouraged or forbidden references
serial to suppress warnings relative to missing serialVersionUID field for a serializable class
static-access o suppress warnings relative to incorrect static access
synthetic-access   to suppress warnings relative to unoptimized access from inner classes
unchecked  to suppress warnings relative to unchecked operations
unqualified-field-access to suppress warnings relative to field access unqualified
unused to suppress warnings relative to unused code

@responseBody注解

的作用是将controller的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,通常用来返回JSON数据或者是XML数据。

@RequestParam注解

将请求参数绑定到你控制器的方法参数上(是springmvc中接收普通参数的注解)

语法:@RequestParam(value=”参数名”,required=”true/false”,defaultValue=””)
value:参数名
required:是否包含该参数,默认为true,表示该请求路径中必须包含该参数,如果不包含就报错。
defaultValue:默认参数值,如果设置了该值,required=true将失效,自动为false,如果没有传该参数,就使用默认值

@Intercepts
Mybatis拦截器实现拦截器,类上面必须添加@Intercepts注解,

@Signature,代表拦截点

属性有:

method表示需要拦截的方法,mybatis有
update, query, flushStatements, commit, rollback, getTransaction, close,
isClosed type表示拦截的接口类型,有Executor、StatementHandler、ParameterHandler和
            ResultSetHandler。 args表示拦截的参数类型,有MappedStatement、Object、RowBounds和ResultHandler等等.

spring-boot 注解集合的更多相关文章

  1. Spring boot注解(annotation)含义详解

    Spring boot注解(annotation)含义详解 @Service用于标注业务层组件@Controller用于标注控制层组件(如struts中的action)@Repository用于标注数 ...

  2. Spring boot 注解简单备忘

    Spring boot 注解简单备忘 1.定义注解 package com.space.aspect.anno;import java.lang.annotation.*; /** * 定义系统日志注 ...

  3. 73. Spring Boot注解(annotation)列表【从零开始学Spring Boot】

    [从零开始学习Spirng Boot-常见异常汇总] 针对于Spring Boot提供的注解,如果没有好好研究一下的话,那么想应用自如Spring Boot的话,还是有点困难的,所以我们这小节,说说S ...

  4. Spring Boot 注解之ObjectProvider源码追踪

    最近依旧在学习阅读Spring Boot的源代码,在此过程中涉及到很多在日常项目中比较少见的功能特性,对此深入研究一下,也挺有意思,这也是阅读源码的魅力之一.这里写成文章,分享给大家. 自动配置中的O ...

  5. Spring Boot注解大全,一键收藏了!

    本文首发于微信公众号[猿灯塔],转载引用请说明出处 今天是猿灯塔“365天原创计划”第5天. 今天呢!灯塔君跟大家讲: Spring Boot注解大全 一.注解(annotations)列表 @Spr ...

  6. (转)spring boot注解 --@EnableAsync 异步调用

    原文:http://www.cnblogs.com/azhqiang/p/5609615.html EnableAsync注解的意思是可以异步执行,就是开启多线程的意思.可以标注在方法.类上. @Co ...

  7. spring boot注解 --@EnableAsync 异步调用

    EnableAsync注解的意思是可以异步执行,就是开启多线程的意思.可以标注在方法.类上. @Component public class Task { @Async public void doT ...

  8. spring boot注解之@Scheduled定时任务实现

    java实现定时任务一般使用timer,或者使用quartz组件.现在在spring boot提供了更加方便的实现方式. spring boot已经集成了定时任务.使用@Secheduled注解. @ ...

  9. Spring Boot 注解的使用

    Spring Boot 优于Spring mvc ,SSM,SSH 的一个亮点就是他使用了好多的注解. 1. @Autowired 这个注解的作用是将其他的类,接口引入,类似于之前的类的初始化等,用这 ...

  10. Spring Boot 注解详解

    一.注解(annotations)列表 @SpringBootApplication:包含了@ComponentScan.@Configuration和@EnableAutoConfiguration ...

随机推荐

  1. 00_UML图形分类

    1.   描述对象 类图(Class Diagram) 包图(Package Diagram) 对象图(Object Diagram) 组件图(Component Diagram) 部署图(Deplo ...

  2. 【windows安全性 之访问控制】 访问控制 详细解说

    windows的安全性的两个基本支柱是身份验证(登入)和授权(访问控制). 身份验证是标识用户的过程 ,授权在验证了所标识用户是否可以访问特定资源之后进行. 相关的命名空间和类: System.Sec ...

  3. 一个简单的性能计数器:CodeTimer

    public static class CodeTimer { public static void Initialize() { Process.GetCurrentProcess().Priori ...

  4. HTML背景图加载过慢解决思路

    压缩图片的大小 第一个压缩图片网站 第二个压缩图片网站

  5. JZ-015-反转链表

    反转链表 题目描述 输入一个链表,反转链表后,输出新链表的表头. 题目链接: 反转链表 代码 /** * 标题:反转链表 * 题目描述 * 输入一个链表,反转链表后,输出新链表的表头. * 题目链接: ...

  6. 『现学现忘』Docker基础 — 9、Docker简介

    目录 1.什么是Docker? 2.Docker的出现解决了什么问题? 3.Docker的特别之处 4.Docker相关网站 1.什么是Docker? 2010年dotCloud公司在旧金山成立,PA ...

  7. Linux du命令和df命令区别

    du 命令 1.命令格式: du [选项][文件] 2.命令功能: 显示每个文件和目录的磁盘使用空间. 3.命令参数: -a或-all 显示目录中个别文件的大小. -b或-bytes 显示目录或文件大 ...

  8. System x 服务器制作ServerGuide U盘安装Windows Server 2012 R2操作系统

    以下内容来源于:联想官方知识库  http://iknow.lenovo.com.cn/detail/dc_154773.html 本例介绍以U盘方式,通过ServerGuide引导在System x ...

  9. 假设检验的python实现命令——Z检验、t检验、F检验

    Z检验 statsmodels.stats.weightstats.ztest() import statsmodels.stats.weightstats as sw 参数详解: x1:待检验数据集 ...

  10. java高并发之ConcurrentSkipListMap的那些事

    注意:本文内容基于JDK11,不同版本会有差异 ConcurrentSkipListMap的结构 ConcurrentSkipListMap是以链表(自然排序)的形式进行数据存储的.即在类中通过定义N ...