本文共 1196 字,大约阅读时间需要 3 分钟。
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 @ComponentScanpublic 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.
转载地址:http://bpxlx.baihongyu.com/