In a Spring Boot starter, the auto-configuration class defines the beans the starter provides, and it is declared with @AutoConfiguration, which is itself a specialised @Configuration. A plain @Configuration class alone is not enough: Spring Boot only loads it automatically if it is listed in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports.
Older tutorials list auto-configuration classes in spring.factories. That registration method was removed for auto-configuration in Spring Boot 3.0, so current starters use the .imports file.
A starter is usually two modules: an autoconfigure module with the code, and a thin starter module that only declares dependencies. The autoconfigure module contains:
@ConfigurationProperties)..imports file that tells Spring Boot the class exists.@Configuration is what lets the class hold @Bean methods. @AutoConfiguration adds the metadata that Spring Boot uses to order it relative to other auto-configurations and to exclude it by name.
@ConditionalOnMissingBean is the key to a polite starter: if the application defines its own GreetingService bean, the starter backs off instead of conflicting. Other useful conditions are @ConditionalOnProperty (feature toggles), @ConditionalOnClass (only when a library is on the classpath) and @ConditionalOnWebApplication.
Create this file in the autoconfigure module's resources:
Its content is one fully qualified class name per line:
Without this file, Spring Boot never sees the class, and the bean silently does not exist. Applications that add the starter to their dependencies can now inject the service:
Setting greeting.message=Welcome in application.properties changes the output to Welcome, Ada! with no code change.
Auto-configuration classes must not be found by the application's own component scan. If they were, they would load without conditions or ordering. That is why they live in a package outside the application's base package, and why they are listed in the .imports file instead of relying on @Component or a scanned @Configuration.
If you want your auto-configuration to run before or after another one, use @AutoConfiguration(after = DataSourceAutoConfiguration.class) or the before attribute.
Use ApplicationContextRunner, which starts a lightweight context without a web server:
Use @AutoConfiguration. It is meta-annotated with @Configuration and is the supported way to mark auto-configuration since Spring Boot 2.7.
For other extension points yes, but not for registering auto-configuration in Spring Boot 3 and later. Use the .imports file.
It controls whether Spring creates a CGLIB proxy so calls between @Bean methods return the same singleton. @AutoConfiguration already sets it to false for speed, so inject dependencies as method parameters instead of calling other @Bean methods.
By defining a bean of the same type in their application, as long as your method uses @ConditionalOnMissingBean.
A starter's configuration class declares the beans and defaults the starter offers. Annotate it with @AutoConfiguration, make every bean conditional so applications can override it, bind settings with @ConfigurationProperties, and register the class in the AutoConfiguration.imports file. Test it with ApplicationContextRunner.