Spring Boot 3: spring.factories
Last updated
Was this helpful?
Last updated
Was this helpful?
In Spring Boot 3, the traditional META-INF/spring.factories
mechanism was replaced by a new metadata-based system using:
META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
(for auto-configuration)
META-INF/spring/org.springframework.boot
folder with structured metadata files for other use cases
Modularity: Split metadata per feature rather than one bulky file
Better performance: Optimized classpath scanning
Clarity: Easier to understand and manage for different framework extension points
Native image compatibility: Improves behavior in GraalVM and AOT (Ahead-of-Time) contexts
EnableAutoConfiguration
Create the file:
Add your class:
Java Class:
This is now the standard way to register auto-configuration classes in Spring Boot 3.
These are not moved to a new system. They still use spring.factories
, even in Spring Boot 3.
So, for the following types, we still use META-INF/spring.factories
:
spring.factories
:ApplicationContextInitializer
Modify application context before refresh
EnvironmentPostProcessor
Add/override environment properties
ApplicationListener
Hook into Spring event lifecycle
SpringApplicationRunListener
Listen to Spring Boot startup phases
Auto Configuration
spring.factories
with EnableAutoConfiguration
key
AutoConfiguration.imports
file
Initializers
spring.factories
still spring.factories
Listeners
spring.factories
still spring.factories
Env Post Processor
spring.factories
still spring.factories
Lifecycle Hooks
spring.factories
still spring.factories