2015-03-19 16:41:06 +00:00
|
|
|
|
### 18. 使用@SpringBootApplication注解
|
|
|
|
|
|
2015-05-16 02:15:35 +00:00
|
|
|
|
很多Spring Boot开发者总是使用`@Configuration`,`@EnableAutoConfiguration`和`@ComponentScan`注解他们的main类。由于这些注解被如此频繁地一块使用(特别是你遵循以上[最佳实践](14. Structuring your code.md)时),Spring Boot提供一个方便的`@SpringBootApplication`选择。
|
2015-03-19 16:41:06 +00:00
|
|
|
|
|
|
|
|
|
该`@SpringBootApplication`注解等价于以默认属性使用`@Configuration`,`@EnableAutoConfiguration`和`@ComponentScan`。
|
|
|
|
|
```java
|
|
|
|
|
package com.example.myproject;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|