We have a library ,in order to auto-configure the library we use spring.factories file under(src/main/resources/META-INF
) which provides classes to auto-configure my library.
Reference : https://docs.spring.io/spring-boot/docs/1.4.0.M3/reference/htmlsingle/#boot-features-custom-starter
I have below configuration in spring.factories file :
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.x.y.PubSubConfig
My understanding is spring.factories is an alternative to configure library and server purpose similar to @SpringBootApplication
in a normal application.
I am doing integration using using @SpringBootTest
, I expect my context to be configured from configuration classes provided by spring.factories. When i run these tests spring does not identify spring.factories and throws an error
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
- If i annotate my
PubSubConfig
with SpringBootApplication then my integration tests run perfectly fine but since it is a library I don't wanna do so. - If I provide my configuration class specifically using
@SpringBootTest(classes = PubSubConfig.class)
my tests run fine.
Now I am trying to understand why I need to do either of above dedicatedly as spring.factories is responsible to do my auto-configure