Based on my testing, I've found no obvious difference when Spring Boot auto-configuration classes have or don't have the @Configuration
annotation - if they are configured in spring.factories
correctly they are loaded regardless of the @Configuration
annotation.
However, it seems like every custom auto-configuration example and demo uses the @Configuration
annotation. Is there a reason all these examples use @Configuration
(or is it just convention)? Is there any impact to not using @Configuration
?
Some examples that use @Configuration
on auto-configuration classes:
- https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.developing-auto-configuration.condition-annotations.class-conditions
- https://www.baeldung.com/spring-boot-custom-auto-configuration#creating-a-custom-auto-configuration
- https://www.baeldung.com/spring-boot-custom-starter#1-auto-configuration-classes
- https://www.javadevjournal.com/spring-boot/spring-boot-custom-starter/
- https://billykorando.com/2019/12/30/building-a-custom-spring-boot-starter/
- http://www.masterspringboot.com/getting-started-with-spring-boot/spring-boot-quickstarts/how-to-build-a-custom-spring-boot-starter-in-no-time/
- https://github.com/snicoll/spring-boot-master-auto-configuration/blob/main/hornetq-spring-boot-autoconfigure/src/main/java/hornetq/autoconfigure/HornetQAutoConfiguration.java