spring_reference/III. Using Spring Boot/18. Using the @SpringBootAp...

21 lines
991 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 18. 使用@SpringBootApplication注解
很多Spring Boot开发者总是使用`@Configuration``@EnableAutoConfiguration`和`@ComponentScan`注解他们的main类。由于这些注解被如此频繁地一块使用特别是你遵循以上[最佳实践](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-structuring-your-code)时Spring Boot提供一个方便的`@SpringBootApplication`选择。
该`@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);
}
}
```