您的位置:首页 > 移动开发

SpringBoot中的注解@SpringBootApplication和(@Configuration......)

2018-03-09 14:23 567 查看

以下选自官方的文档

这里写链接内容

Many Spring Boot developers always have their main class annotated with

@Configuration,

@EnableAutoConfiguration,

@ComponentScan.

Since these annotations are so frequently used together (especially if you follow the best practices above), Spring Boot provides a convenient @SpringBootApplication alternative.

翻译:许多SpringBoot的开发者都喜欢在主方法中注解。

因为这些注解是很频繁的在一起使用,SpringBoot提供了一个更加便捷的注解@SpringBootApplication,来替代三个一起使用。

意思就是:一个抵三个。

@Configuration:配置

@EnableAutoConfiguration:自动加载配置

@ComponentScan:扫描指定的包

The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with their default attributes, as shown in the following example:

package com.example.myapplication;

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);
}

}


ps:@SpringBootApplication also provides aliases to customize the attributes of @EnableAutoConfiguration and @ComponentScan.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息