spring-boot 注解集合
@Configuration
@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 注解集合的更多相关文章
- Spring boot注解(annotation)含义详解
Spring boot注解(annotation)含义详解 @Service用于标注业务层组件@Controller用于标注控制层组件(如struts中的action)@Repository用于标注数 ...
- Spring boot 注解简单备忘
Spring boot 注解简单备忘 1.定义注解 package com.space.aspect.anno;import java.lang.annotation.*; /** * 定义系统日志注 ...
- 73. Spring Boot注解(annotation)列表【从零开始学Spring Boot】
[从零开始学习Spirng Boot-常见异常汇总] 针对于Spring Boot提供的注解,如果没有好好研究一下的话,那么想应用自如Spring Boot的话,还是有点困难的,所以我们这小节,说说S ...
- Spring Boot 注解之ObjectProvider源码追踪
最近依旧在学习阅读Spring Boot的源代码,在此过程中涉及到很多在日常项目中比较少见的功能特性,对此深入研究一下,也挺有意思,这也是阅读源码的魅力之一.这里写成文章,分享给大家. 自动配置中的O ...
- Spring Boot注解大全,一键收藏了!
本文首发于微信公众号[猿灯塔],转载引用请说明出处 今天是猿灯塔“365天原创计划”第5天. 今天呢!灯塔君跟大家讲: Spring Boot注解大全 一.注解(annotations)列表 @Spr ...
- (转)spring boot注解 --@EnableAsync 异步调用
原文:http://www.cnblogs.com/azhqiang/p/5609615.html EnableAsync注解的意思是可以异步执行,就是开启多线程的意思.可以标注在方法.类上. @Co ...
- spring boot注解 --@EnableAsync 异步调用
EnableAsync注解的意思是可以异步执行,就是开启多线程的意思.可以标注在方法.类上. @Component public class Task { @Async public void doT ...
- spring boot注解之@Scheduled定时任务实现
java实现定时任务一般使用timer,或者使用quartz组件.现在在spring boot提供了更加方便的实现方式. spring boot已经集成了定时任务.使用@Secheduled注解. @ ...
- Spring Boot 注解的使用
Spring Boot 优于Spring mvc ,SSM,SSH 的一个亮点就是他使用了好多的注解. 1. @Autowired 这个注解的作用是将其他的类,接口引入,类似于之前的类的初始化等,用这 ...
- Spring Boot 注解详解
一.注解(annotations)列表 @SpringBootApplication:包含了@ComponentScan.@Configuration和@EnableAutoConfiguration ...
随机推荐
- Another app is currently holding the yum lock解决方法
用yum安装包有时候会提示 ``` Another app is currently holding the yum lock; waiting for it to exit... The oth ...
- [gRPC via C#] gRPC本质的探究与实践
鉴于内容过多,先上太长不看版: grpc 就是请求流&响应流特殊一点的 Http 请求,性能和 WebAPI 比起来只快在 Protobuf 上: 附上完整试验代码:GrpcWithOutSD ...
- Oracle 添加用户并赋权,修改密码,解锁,删除用户的方法
转至:https://www.jb51.net/article/20367.htm 添加用户(随着用户的创建,自动产生与用户同名的schema) CREATE USER "TESTER&qu ...
- WIN10:显示隐藏文件夹
AppData是默认隐藏文件夹,可以通过工具栏显示隐藏项目显示
- LeetCode-006-Z 字形变换
Z 字形变换 题目描述:将一个给定字符串 s 根据给定的行数 numRows ,以从上往下.从左到右进行 Z 字形排列. 比如输入字符串为 "PAYPALISHIRING" 行数为 ...
- Spring Cloud Gateway actuator组建对外暴露RCE问题漏洞分析
Spring Cloud gateway是什么? Spring Cloud Gateway是Spring Cloud官方推出的第二代网关框架,取代Zuul网关.网关作为流量的,在微服务系统中有着非常作 ...
- 如何使用在线工具手动验证JWT签名
如何使用在线工具手动验证JWT签名 先丢一个转换地址:https://cryptii.com/ 首先: jwt分为三个部分:header,payload,verifysignature ...
- 2022年官网下安装RedisDesktopManager最全版与官网查阅方法
目录 安装部署RedisDesktopManager 一.下载安装 1.浏览器输入网址:https://github.com/ ,输入搜索条件,找到如图,双击 2.滑动浏览器找到如图位置,双击 3.滑 ...
- SpringBoot接入轻量级分布式日志框架(GrayLog)
我是3y,一年CRUD经验用十年的markdown程序员常年被誉为优质八股文选手 前两天我不是发了一篇数据链路追踪的文章嘛,在末尾也遗留了TODO:运行应用的服务器一般是集群,日志数据会记录到不同的 ...
- Kendo UI Grid 批量编辑使用总结
项目中使用Kendo UI Grid控件实现批量编辑,现在将用到的功能总结一下. 批量编辑基本设置 Kendo Grid的设置方法如下: $("#grid").kendoGrid( ...