spring_reference/III. Using Spring Boot/16. Auto-configuration.md

8 lines
587 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.

### 16. 自动配置
Spring Boot自动配置auto-configuration尝试根据你添加的jar依赖自动配置你的Spring应用。例如如果你的classpath下存在`HSQLDB`并且你没有手动配置任何数据库连接beans那么我们将自动配置一个内存型in-memory数据库。
你可以通过将`@EnableAutoConfiguration`或`@SpringBootApplication`注解添加到一个`@Configuration`类上来选择自动配置。
**注**:你只需要添加一个`@EnableAutoConfiguration`注解。我们建议你将它添加到主`@Configuration`类上。