EnableAutoConfiguration (Spring Boot 3.4.5 API) (original) (raw)
Enable auto-configuration of the Spring Application Context, attempting to guess and configure beans that you are likely to need. Auto-configuration classes are usually applied based on your classpath and what beans you have defined. For example, if you have tomcat-embedded.jar
on your classpath you are likely to want aTomcatServletWebServerFactory (unless you have defined your ownServletWebServerFactory bean).
When using @SpringBootApplication, the auto-configuration of the context is automatically enabled and adding this annotation has therefore no additional effect.
Auto-configuration tries to be as intelligent as possible and will back-away as you define more of your own configuration. You can always manually exclude() any configuration that you never want to apply (use excludeName() if you don't have access to them). You can also exclude them through thespring.autoconfigure.exclude
property. Auto-configuration is always applied after user-defined beans have been registered.
The package of the class that is annotated with @EnableAutoConfiguration
, usually through @SpringBootApplication
, has specific significance and is often used as a 'default'. For example, it will be used when scanning for @Entity
classes. It is generally recommended that you place @EnableAutoConfiguration
(if you're not using @SpringBootApplication
) in a root package so that all sub-packages and classes can be searched.
Auto-configuration classes are regular Spring @Configuration beans. They are located using ImportCandidates. Generally auto-configuration beans are @Conditional beans (most often using@ConditionalOnClass and@ConditionalOnMissingBean annotations).
Since:
1.0.0
Author:
Phillip Webb, Stephane Nicoll
See Also:
Optional Element Summary
Optional Elements
Exclude specific auto-configuration classes such that they will never be applied.
Exclude specific auto-configuration class names such that they will never be applied.
Field Summary
Fields
Environment property that can be used to override when auto-configuration is enabled.
Field Details
ENABLED_OVERRIDE_PROPERTY
static final String ENABLED_OVERRIDE_PROPERTY
Environment property that can be used to override when auto-configuration is enabled.
See Also:
* Constant Field ValuesElement Details
exclude
Exclude specific auto-configuration classes such that they will never be applied.
Returns:
the classes to exclude
Default:
{}excludeName
Exclude specific auto-configuration class names such that they will never be applied.
Returns:
the class names to exclude
Since:
1.3.0
Default:
{}