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启动的类

  1. @Target(ElementType.TYPE)
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @Documented
  4. @Inherited
  5. @SpringBootConfiguration
  6. @EnableAutoConfiguration
  7. @ComponentScan(excludeFilters = {
  8. @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
  9. @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
  10. public @interface SpringBootApplication {
  11. @AliasFor(annotation = EnableAutoConfiguration.class, attribute = "exclude")
  12. Class<?>[] exclude() default {};
  13. @AliasFor(annotation = EnableAutoConfiguration.class, attribute = "excludeName")
  14. String[] excludeName() default {};
  15. @AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
  16. String[] scanBasePackages() default {};
  17. @AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
  18. Class<?>[] scanBasePackageClasses() default {};
  19. }

其中有3个注解是我们所关心的:

  1. @SpringBootConfiguration
  2. @EnableAutoConfiguration
  3. @ComponentScan

2.@SpringBootConfiguration —— 通过bean对象来获取配置信息

  1. @Target(ElementType.TYPE)
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @Documented
  4. @Configuration
  5. public @interface SpringBootConfiguration {
  6. }

这个注解是空的,什么都没有,但是他被另一个注解所修饰——@Configuration

3.@Configuration —— 通过对bean对象的操作替代Spring中的xml文件

  1. @Target(ElementType.TYPE)
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @Documented
  4. @Component
  5. public @interface Configuration {
  6. String value() default "";
  7. }

4.@EnableAutoConfiguration —— 根据导入的jar包创建启动环境

  1. @SuppressWarnings("deprecation")
  2. @Target(ElementType.TYPE)
  3. @Retention(RetentionPolicy.RUNTIME)
  4. @Documented
  5. @Inherited
  6. @AutoConfigurationPackage
  7. @Import(EnableAutoConfigurationImportSelector.class)
  8. public @interface EnableAutoConfiguration {
  9. String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";
  10. /**
  11. * Exclude specific auto-configuration classes such that they will never be applied.
  12. * @return the classes to exclude
  13. */
  14. Class<?>[] exclude() default {};
  15. /**
  16. * Exclude specific auto-configuration class names such that they will never be
  17. * applied.
  18. * @return the class names to exclude
  19. * @since 1.3.0
  20. */
  21. String[] excludeName() default {};
  22. }

5.@ComponentScan —— 完成spring的组件扫描

代替了xml文件中的:

  1. <context:component-scan pacage=”....”></context:component-scan>

6.@RestController —— 一个Controller 且该controller下的所有数据以json格式的数据响应

  1. @Target(ElementType.TYPE)
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @Documented
  4. @Controller
  5. @ResponseBody
  6. public @interface RestController {
  7. String value() default "";
  8. }

他被@Controller 和 @ResponseBody 同时修饰 , 因此@RestController = @Controller + @ResponseBody

【SpringBoot】15. Spring Boot核心注解的更多相关文章

  1. 3个Spring Boot核心注解,你知道几个?

    Spring Boot 核心注解讲解 Spring Boot 最大的特点是无需 XML 配置文件,能自动扫描包路径装载并注入对象,并能做到根据 classpath 下的 jar 包自动配置. 所以 S ...

  2. Spring Boot 核心注解与配置文件

    @SpringBootApplication注解 Spring Boot项目有一个入口类 (*Application) 在这个类中有一个main 方法,是运行该项目的切入点.而@SpringBootA ...

  3. 深入了解Spring Boot 核心注解原理

    SpringBoot目前是如火如荼,所以今天就跟大家来探讨下SpringBoot的核心注解@SpringBootApplication以及run方法,理解下springBoot为什么不需要XML,达到 ...

  4. Spring Boot核心注解@SpringBootApplication

    一.作用   @SpringBootApplication是一个组合注解,用于快捷配置启动类. 二.用法   可配置多个启动类,但启动时需选择以哪个类作为启动类来启动项目. 三.拆解 1.拆解     ...

  5. Spring Boot核心注解

    (1)@SpringBootApplication 代表SpringBoot的启动类 (2)@SpringBootConfiguration 通过bean对象来获取配置信息 (3)@Configura ...

  6. Spring Boot核心原理

    Spring Boot核心原理 spring-boot-starter-xxx  方便开发和配置 1.没有depoy setup tomcat 2.xml文件里面的没有没有了 @SpringBootA ...

  7. 【SpringBoot】Spring Boot,开发社区讨论交流网站首页。

    初识Spring Boot,开发社区讨论交流网站首页. 文章目录 初识Spring Boot,开发社区讨论交流网站首页. 1.项目简介 2. 搭建开发环境 JDK Apache Maven Intel ...

  8. Spring Boot 核心配置文件 bootstrap & application

    Spring Boot 核心配置文件 bootstrap & application 1.SpringBoot bootstrap配置文件不生效问题 2.bootstrap/ applicat ...

  9. Spring Boot 常用注解汇总

    一.启动注解 @SpringBootApplication @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documen ...

随机推荐

  1. Espruino似乎和Arduino一样

    参考:https://baike.baidu.com/item/Espruino Espruino 编辑 锁定 讨论   Espruino 是一个微处理器的 JavaScript 解释器,我们用它来创 ...

  2. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)解决方案

    在Win7下使用MySQL5.6.35创建用户时,提示权限不足,具体解决方案如下: 1 停止mysql服务 net stop mysql 2 打开新的cmd窗口,切换到bin目录,运行如下命令,cmd ...

  3. nginx的脚本引擎(一)

    nginx的脚本的语法和shell是很像的,我大致看了一下觉得挺有意思的,就想写写记录一下.我没看过shell脚本的引擎,不知道nginx脚本引擎和shell脚本引擎像不像,但是我觉得nginx的脚本 ...

  4. Git hub加载慢?下载慢?浏览慢?几个小技巧让你一键起飞!

    记得,那是一个风和日丽,艳阳高照的夜晚,只因为当初的一次回眸,于是便决然走向了程序员的道路,从此,CV大法心中记,代码伴我身. 这一天,正当我打开电脑准备开开心心的使用CV大法完成任务的时候,却恼人的 ...

  5. 营口6378.7939(薇)xiaojie:营口哪里有xiaomei

    营口哪里有小姐服务大保健[微信:6378.7939倩儿小妹[营口叫小姐服务√o服务微信:6378.7939倩儿小妹[营口叫小姐服务][十微信:6378.7939倩儿小妹][营口叫小姐包夜服务][十微信 ...

  6. MeteoInfoLab脚本示例:风场矢量图

    读取风场U/V变量数据,可以从U/V计算出风速:speed = sqrt(u*u+v*v).quiverm函数用来绘制风场矢量图,参数中包括U/V变量,如果要绘制彩色风场还需要第三个变量,这里是风速s ...

  7. python接口测试之excel的操作

    1 用到的第三方库openpyxl,需要在命令窗口中下载安装pip install openpyxl,主要对xlsx格式的excel进行读取和编辑: xlrd库从excel中读取数据,支持xlsx x ...

  8. BUUCTF-[极客大挑战 2019]HardSQL 1详解

    来到sql注入骚姿势,我们一点一点开始学 我们来到这道题,然后尝试注入,结果发现 拼接'or '1'='1 'or '1'='2如果是字符型注入则会报错,然而并没有而是显示的页面一样, 通过常规注入, ...

  9. spring boot:redis+lua实现生产环境中可用的秒杀功能(spring boot 2.2.0)

    一,秒杀需要具备的功能: 秒杀通常是电商中用到的吸引流量的促销活动方式 搭建秒杀系统,需要具备以下几点: 1,限制每个用户购买的商品数量,(秒杀价格为吸引流量一般会订的很低,不能让一个用户全部抢购到手 ...

  10. centos8平台使用loginctl管理登录用户与session

    一,loginctl的用途: 控制 systemd 登录管理器 管理当前登录的用户和session 说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/a ...