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个注解是我们所关心的:

  1. @SpringBootConfiguration
  2. @EnableAutoConfiguration
  3. @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核心注解的更多相关文章

  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. matlab中nargin函数输入参数数目

    来源:https://ww2.mathworks.cn/help/matlab/ref/nargin.html?searchHighlight=nargin&s_tid=doc_srchtit ...

  2. P2832 行路难

    题面 Link 题目背景 小X来到了山区,领略山林之乐.在他乐以忘忧之时,他突然发现,开学迫在眉睫 题目描述 山区有 \(n\) 座山.山之间有 \(m\) 条羊肠小道,每条连接两座山,只能单向通过, ...

  3. iPhone手机越狱-逆向砸壳-代码注入

    iPhone手机越狱 逆向砸壳 代码注入 工具下载 操作越狱 安装待逆向应用(app) 使用OpenSSH连接手机 找到应用二进制文件地址 找到应用document沙盒地址 拷贝砸壳工具(dumpde ...

  4. jquery购物车全选,取消全选,计算总金额

    这是html代码 <div class="gwcxqbj"> <div class="gwcxd center"> <div cl ...

  5. Martyr2项目实现——Number部分的问题求解 (1) Find Pi to Nth Digit

    Martyr2项目实现--Number部分的问题求解 (1) Find Pi to Nth Digit Find Pi to Nth Digit 问题描述: Find PI to the Nth Di ...

  6. centos8环境安装配置rsync

    一,查看本地centos的版本: [root@localhost lib]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core) ...

  7. centos6.8 架设 Telnet 服务

    centos6.8 架设 Telnet 非常简单 百度云下载RPM,然后上传到服务器 链接:https://pan.baidu.com/s/1w91HBf1TOJsZsqBMQnO7tA 提取码:au ...

  8. Redis Lua脚本完全入门

    1. 前言 Redis是高性能的KV内存数据库,除了做缓存中间件的基本作用外还有很多用途,比如胖哥以前分享的Redis GEO地理位置信息计算.Redis提供了丰富的命令来供我们使用以实现一些计算.R ...

  9. SpringBoot整合日志log4j2

    SpringBoot整合日志log4j2 一个项目框架中日志都是必不可少的,随着技术的更新迭代,SpringBoot被越来越多的企业所采用.这里简单说说SpringBoot整合log2j2日志. 一. ...

  10. Maven1详解

    Maven详解(一)------ Maven概述   目录 1.引言 2.常规项目开发存在的问题 3.什么是 Maven ? 4.Maven 的历史 5.Maven 的目标 6.Maven 的理念 回 ...