Configuration Classes
| This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Boot 4.1.1! |
Spring Boot favors Java-based configuration.
Although it is possible to use SpringApplication with XML sources, we generally recommend that your primary source be a single @Configuration class.
Usually the class that defines the main method is a good candidate as the primary @Configuration.
Many Spring configuration examples have been published on the Internet that use XML configuration. If possible, always try to use the equivalent Java-based configuration. Searching for Enable* annotations can be a good starting point. |
Importing Additional Configuration Classes
You need not put all your @Configuration into a single class.
The @Import annotation can be used to import additional configuration classes.
Alternatively, you can use @ComponentScan to automatically pick up all Spring components, including @Configuration classes.
Importing XML Configuration
If you absolutely must use XML based configuration, we recommend that you still start with a @Configuration class.
You can then use an @ImportResource annotation to load XML configuration files.
- Related Spring Documentation
- Spring Boot
- Spring Framework
- Spring Cloud
- Spring Cloud Build
- Spring Cloud Bus
- Spring Cloud Circuit Breaker
- Spring Cloud Commons
- Spring Cloud Config
- Spring Cloud Consul
- Spring Cloud Contract
- Spring Cloud Function
- Spring Cloud Gateway
- Spring Cloud Kubernetes
- Spring Cloud Netflix
- Spring Cloud OpenFeign
- Spring Cloud Stream
- Spring Cloud Task
- Spring Cloud Vault
- Spring Cloud Zookeeper
- Spring Data
- Spring Integration
- Spring Batch
- Spring Security
- Spring AI
- Spring AMQP
- Spring CLI
- Spring GraphQL
- Spring for Apache Kafka
- Spring Modulith
- Spring for Apache Pulsar
- Spring Shell All Docs...
