Spring Boot 3: spring.factories
About
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.bootfolder with structured metadata files for other use cases

Why the Change ?
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
Replacing EnableAutoConfiguration
EnableAutoConfigurationOld Way (Spring Boot 2):
propertiesCopyEdit# spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.example.autoconfig.MyAutoConfigurationNew Way (Spring Boot 3):
Create the file:
META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.importsAdd your class:
com.example.autoconfig.MyAutoConfigurationJava Class:
@Configuration
@ConditionalOnClass(name = "com.example.MyService")
public class MyAutoConfiguration {
@Bean
public MyService myService() {
return new MyService();
}
}This is now the standard way to register auto-configuration classes in Spring Boot 3.
ApplicationContextInitializer, EnvironmentPostProcessor, RunListener
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:
Still supported in Spring Boot 3 via 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
Example:
# META-INF/spring.factories
org.springframework.boot.env.EnvironmentPostProcessor=\
com.example.env.MyEnvPostProcessorpublic class MyEnvPostProcessor implements EnvironmentPostProcessor {
public void postProcessEnvironment(ConfigurableEnvironment env, SpringApplication app) {
env.getSystemProperties().put("env.source", "custom");
}
}Comparison
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
Last updated