【SpringBoot】15. Spring Boot核心注解
Spring Boot核心注解
| 1 | @SpringBootApplication | 代表是Spring Boot启动的类 |
|---|---|---|
| 2 | @SpringBootConfiguration | 通过bean对象来获取配置信息 (被@Configuration修饰所以才能够获取配置信息) |
| 3 | @Configuration | 通过对bean对象的操作替代spring中的xml文件 |
| 4 | @EnableAutoConfiguration | 完成一些初始化环境的配置 |
| 5 | @ComponentScan | 完成spring的组件扫描。替代之前在xml文件中配置组件扫描的配置(context:component-scan pacage=”....”) |
| 6 | @RestController | 1,表示一个 Controller。2,表示当前这个 Controller 下的所有的方法都会以 json 格式的数据响应。 和 @Controller + @ResponseBody组合使用一样。 |
1.@SpringBootApplication —— Spring Boot启动的类
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
@Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {
@AliasFor(annotation = EnableAutoConfiguration.class, attribute = "exclude")
Class<?>[] exclude() default {};
@AliasFor(annotation = EnableAutoConfiguration.class, attribute = "excludeName")
String[] excludeName() default {};
@AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
String[] scanBasePackages() default {};
@AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
Class<?>[] scanBasePackageClasses() default {};
}
其中有3个注解是我们所关心的:
- @SpringBootConfiguration
- @EnableAutoConfiguration
- @ComponentScan
2.@SpringBootConfiguration —— 通过bean对象来获取配置信息
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
public @interface SpringBootConfiguration {
}
这个注解是空的,什么都没有,但是他被另一个注解所修饰——@Configuration
3.@Configuration —— 通过对bean对象的操作替代Spring中的xml文件
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Configuration {
String value() default "";
}
4.@EnableAutoConfiguration —— 根据导入的jar包创建启动环境
@SuppressWarnings("deprecation")
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import(EnableAutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration {
String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";
/**
* Exclude specific auto-configuration classes such that they will never be applied.
* @return the classes to exclude
*/
Class<?>[] exclude() default {};
/**
* Exclude specific auto-configuration class names such that they will never be
* applied.
* @return the class names to exclude
* @since 1.3.0
*/
String[] excludeName() default {};
}
5.@ComponentScan —— 完成spring的组件扫描
代替了xml文件中的:
<context:component-scan pacage=”....”></context:component-scan>
6.@RestController —— 一个Controller 且该controller下的所有数据以json格式的数据响应
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@ResponseBody
public @interface RestController {
String value() default "";
}
他被@Controller 和 @ResponseBody 同时修饰 , 因此@RestController = @Controller + @ResponseBody
【SpringBoot】15. Spring Boot核心注解的更多相关文章
- 3个Spring Boot核心注解,你知道几个?
Spring Boot 核心注解讲解 Spring Boot 最大的特点是无需 XML 配置文件,能自动扫描包路径装载并注入对象,并能做到根据 classpath 下的 jar 包自动配置. 所以 S ...
- Spring Boot 核心注解与配置文件
@SpringBootApplication注解 Spring Boot项目有一个入口类 (*Application) 在这个类中有一个main 方法,是运行该项目的切入点.而@SpringBootA ...
- 深入了解Spring Boot 核心注解原理
SpringBoot目前是如火如荼,所以今天就跟大家来探讨下SpringBoot的核心注解@SpringBootApplication以及run方法,理解下springBoot为什么不需要XML,达到 ...
- Spring Boot核心注解@SpringBootApplication
一.作用 @SpringBootApplication是一个组合注解,用于快捷配置启动类. 二.用法 可配置多个启动类,但启动时需选择以哪个类作为启动类来启动项目. 三.拆解 1.拆解 ...
- Spring Boot核心注解
(1)@SpringBootApplication 代表SpringBoot的启动类 (2)@SpringBootConfiguration 通过bean对象来获取配置信息 (3)@Configura ...
- Spring Boot核心原理
Spring Boot核心原理 spring-boot-starter-xxx 方便开发和配置 1.没有depoy setup tomcat 2.xml文件里面的没有没有了 @SpringBootA ...
- 【SpringBoot】Spring Boot,开发社区讨论交流网站首页。
初识Spring Boot,开发社区讨论交流网站首页. 文章目录 初识Spring Boot,开发社区讨论交流网站首页. 1.项目简介 2. 搭建开发环境 JDK Apache Maven Intel ...
- Spring Boot 核心配置文件 bootstrap & application
Spring Boot 核心配置文件 bootstrap & application 1.SpringBoot bootstrap配置文件不生效问题 2.bootstrap/ applicat ...
- Spring Boot 常用注解汇总
一.启动注解 @SpringBootApplication @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documen ...
随机推荐
- BSGS算法解析
前置芝士: 1.快速幂(用于求一个数的幂次方) 2.STL里的map(快速查找) 详解 BSGS 算法适用于解决高次同余方程 \(a^x\equiv b (mod p)\) 由费马小定理可得 x &l ...
- ORA-28001: the password has expired 密码已过期
ORA-28001: the password has expiredORA-28001: 密码已过期 Cause: The user's account has expired and ...
- ansible-命令使用说明
1. ansible命令的使用说明 ansible 主机或组-m 模块名-a '模块参数' ansible参数 表示调用什么模块,使用模块的那些参数 • 主机和组,是在/etc/ansible/hos ...
- ubuntu19.10 系统需要安装的软件
将ubuntu18 升级到ubuntu19 期间好几次卡在启动界面,比较担心要不要重装系统,有幸后来正常了.明显感觉操作快了不少.下半年稳定版就出来,到时候免不了再折腾一番,提前把安全记录做好. 下面 ...
- docker容器命令1
docker容器命令 新建并启动容器命令 docker run INAME(镜像名字) 语法:docker run [OPTIONS] INAME [COMMAND] 例子:docker run -i ...
- 多测师讲解python _练习题002_高级讲师肖sir
# 1.求出1/1+1/3+1/5--+1/99的和 # 2.用循环语句,计算2-10之间整数的循环相乘的值. # 3.用for循环打印九九乘法表 # 4.求每个字符串中字符出现的个数如:hellow ...
- vs code个性化设置
文件=>首选项=>设置,直接在搜索栏搜索有背景色的部分即可 1. 鼠标滚轮缩放 "editor.mouseWheelZoom": true 2. 显示空格和tab符号 ...
- 【C语言C++编程入门】——程序结构:构思!
学习编程语言的最好方法是编写程序.一般来说,初学者编写的第一个程序是一个名为"Hello World"的程序,它简单地将"Hello World"打印到你的电脑 ...
- Shell Scripting 笔记
Shell Scripting Tutorial Variables in the Bourne shell do not have to be declared, as they do in lan ...
- kafka-伪集群搭建
一.简介 Apache Kafka是一个快速.可扩展的.高吞吐的.可容错的分布式"发布-订阅"消息系统,使用Scala与Java语言编写,能够将消息从一个端点传递到另一个端点, ...