Spring Boot 2: spring.factories
About
Where Is It Located?
src/main/resources/META-INF/spring.factoriesFormat of the File
# Format:
<interface or annotation>=<implementation class 1>,<implementation class 2>,...
# Example for auto-configuration:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.example.config.MyAutoConfiguration
Common Keys Used in spring.factories
Key
Purpose
When to Use spring.factories
Examples with Spring Boot 2
1. org.springframework.boot.autoconfigure.EnableAutoConfiguration
Use Case
Code Example
2. org.springframework.context.ApplicationListener
Use Case
Code Example
3. org.springframework.context.ApplicationContextInitializer
Use Case
Code Example
4. org.springframework.boot.env.EnvironmentPostProcessor
Use Case
Code Example
5. org.springframework.boot.SpringApplicationRunListener
Use Case
Code Example
Comparison
Key
When It Runs
Purpose
Common Use
Why and When to use spring.factories instead of @Component or @Configuration ?
When to Use @Component / @Configuration
Example:
When to Use spring.factories
Example
If we use @Component
If we use spring.factories
Last updated