SpringBoot的注解:@SpringBootApplication注解 vs @EnableAutoConfiguration+@ComponentScan+@Configuration
spring Boot开发者经常使用@Configuration,@EnableAutoConfiguration,@ComponentScan注解他们的main类,
由于这些注解如此频繁地一块使用(特别是遵循以上最佳实践的时候),Spring Boot就提供了一个方便的@SpringBootApplication注解作为代替。
@SpringBootApplication注解等价于以默认属性使用@Configuration,@EnableAutoConfiguration和@ComponentScan:
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
注 @SpringBootApplication注解也提供了用于自定义@EnableAutoConfiguration和@ComponentScan属性的别名(aliases)。
SpringBoot的注解:@SpringBootApplication注解 vs @EnableAutoConfiguration+@ComponentScan+@Configuration的更多相关文章
- springboot情操陶冶-@SpringBootApplication注解解析
承接前文springboot情操陶冶-@Configuration注解解析,本文将在前文的基础上对@SpringBootApplication注解作下简单的分析 @SpringBootApplicat ...
- SpringBoot学习之@SpringBootApplication注解
下面是我们经常见到SpringBoot启动类代码: @SpringBootApplicationpublic class DemoApplication extends SpringBootServl ...
- Springboot系列:@SpringBootApplication注解
在使用 Springboot 框架进行开发的时候,通常我们会在 main 函数上添加 @SpringBootApplication 注解,今天为大家解析一下 @SpringBootApplicatio ...
- 品 SpringBootApplication 注解源码
@SpringBootApplication 由以下三个注解构成: @SpringBootConfiguration@EnableAutoConfiguration@ComponentScan 一:@ ...
- 03.父工程pom、整合测试、SpringBootApplication注解
父工程 idea点击spring-boot-starter-parent找到父工程spring-boot-dependencies模仿配置 父工程 <?xml version="1.0 ...
- Springboot启动类及注解说明
Spring boot的启动是基于main方法的,其主要注解为: 1. @springBootApplication:项目的启动注解,是一个组合注解,包含@SpringbootConfiguratio ...
- Springboot ,1开启配置与2.扫描包(控制层,service层)二个注解@EnableAutoConfiguration,@ComponentScan 合并成一个注解@SpringBootApplication
//@EnableAutoConfiguration//@ComponentScan(value= {"com.foen.cloud.controller.*","com ...
- 【spring boot】注解@SpringBootApplication 相当于 @Configuration、@EnableAutoConfiguration 、 @ComponentScan 三个的作用
注解@SpringBootApplication 相当于 @Configuration.@EnableAutoConfiguration . @ComponentScan 三个的作用 代码示例:Git ...
- @EnableAutoConfiguration和@SpringbootApplication注解
一.@EnableAutoConfiguration 这个注释告诉SpringBoot“猜”你将如何想配置Spring,基于你已经添加jar依赖项.如果spring-boot-starter-web已 ...
随机推荐
- thoughtworks面试题分析与解答
题目描述 A squad of robotic rovers are to be landed by NASA on a plateau on Mars. This plateau, which is ...
- .msi安装包安装方法(安装错误2503和2502)
把鼠标放到Win8屏幕的最左下角,等待Win8 Metro界面的缩略图出现后点击鼠标右键,在弹出的菜单中选择“命令提示符(管理员)”在“命令提示符(管理员)”中输入 msiexec /package ...
- 【Unity与23种设计模式】装饰模式(Decorator)
GoF中定义: "动态地附加额外的责任给一个对象.装饰模式提供了一个灵活的选择,让子类可以用来扩展功能." 装饰模式一般用来增加新功能 它可以避免更改已经实现的程序代码 从而增加系 ...
- 我的linux学习之路——(一)
prompt:命令提示符 命令: command options...... arguments...... 选项: 短选项 长选项 带参数的选项 参数: list----ls 列出,列表 列出制定路 ...
- 给定n,求1/x + 1/y = 1/n (x<=y)的解数~hdu-1299~(分解素因子详解)
链接:https://www.nowcoder.com/acm/contest/90/F来源:牛客网 题目描述 给定n,求1/x + 1/y = 1/n (x<=y)的解数.(x.y.n均为正整 ...
- Redis主从集群的Sentinel配置
http://www.cnblogs.com/LiZhiW/p/4851631.html
- redis集群离线安装
环境准备: redis-4.0.7.tar.gz redis的安装包 Ruby环境(集群搭建需要用ruby创建, ruby环境在2.2以上.) rubygems-2.7.4.tgz 和 redis-3 ...
- JVM学习六:JVM之类加载器之双亲委派机制
前面我们知道类加载有系统自带的3种加载器,也有自定义的加载器,那么这些加载器之间的关系是什么,已经在加载类的时候,谁去加载呢?这节,我们将进行讲解. 一.双亲委派机制 JVM的ClassLoader采 ...
- java 定义泛型方法
1 class Demo{ 2 public <T> T fun(T t){ 3 return t; 4 } 5 } 6 public class GenericsDemo { 7 pub ...
- PHP 设计模式阅读清单
社区文章推荐 S.O.L.I.D 面向对象设计和编程(OOD&OOP)笔记 浅谈 Laravel 设计模式 PHP 完整实战 23 种设计模式 Laravel Dependency Injec ...