@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. kali linux 安装lanmp遇到的问题

    安装LANMP步骤(需要ROOT权限)2020版本以上的Linux kali需要百度参考修改权限得文章 root@kali:~# wget http://dl.wdlinux.cn/files/lan ...

  2. ctf平台

    CTF靶场 蓝鲸安全:http://whalectf.xin bugku:https://ctf.bugku.com XCTF攻防世界:https://adworld.xctf.org.cn/ i春秋 ...

  3. 网络测试技术——802.1X_MD5认证(上篇)

    一.MD5认证简介 1.认证过程 (1)无隧道 (2)客户端和服务器之间进行 2.单向认证 (1)服务器对客户端认证 3.缺点 (1)用户名明文传输 (2)弱MD5哈希   二.MD5认证过程 1.客 ...

  4. SaaS平台是什么,为什么字节、腾讯等大厂都在抢相关人才

    SaaS平台很多人可能没听说是什么,但是从事TO  B公司的员工来说,SaaS平台应该都有所耳闻.从2016年开始,腾讯开始发力TO B算起,到处在挖TO B公司的骨干人才,而熟悉SaaS平台的人才竞 ...

  5. Oracle之非关系数据库

    什么是非关系型数据库? 非关系型数据库它的全称是Not Only SQL(简称 NoSQL数据库)是用于存储和检索数据的非关系数据库系统.在当今世界,我们不应该只以没有预定义固定模式的表格式存储所有数 ...

  6. unittest的discover方法批量执行02

    前言 我们在写用例的时候,单个脚本的用例好执行,那么多个脚本的时候,如何批量执行呢?这时候就需要用到unittet里面的discover方法来加载用例了. 加载用例后,用unittest里面的Text ...

  7. redirect route 路由传参

    return redirect()->route('exams.sign',['token'=>$token,'id'=>$result['id']]); // 签到页面 Route ...

  8. laravel 使用Redis

    1.非框架中使用redis实例? 就是new出redis对象然后连接,然后键值操作即可 <?php $redis = new redis(); $redis->connect('127.0 ...

  9. 如何取消 UIView 动画?

    原文链接 最近项目中有一个需求是需要手动点击相机对焦,这里由于相机对焦部分需要一个类似于系统对焦框一样的缩放动画,同时动画时长为0.3秒,因此这里就有一个很普遍的需求,如果用户在0.3秒内继续点击对焦 ...

  10. 基于python 实现冒泡排序算法

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/11/17 14:42 # @Author : gylhaut # @Site ...