1

We have created a custom spring boot starter which holds several common feature reusable cross internal projects. The starter is working fine as expected. However, while integration test, the projects using the starter are not able to find all beans created by the custom starter.

NB: The internal project are using in their integration test class the annotation @SpringBootTest in order to load the whole spring context.

Katy
  • 1,023
  • 7
  • 19
  • If the starter works at runtime it should also work in a test annotated `@SpringBootTest`. In both cases, the starter's auto-configuration classes should be found via an entry in `spring.factories`. Can you provide a [minimal, complete, and verifiable example](/help/mcve) that is representative of your custom starter and shows things working at runtime but not working in an integration test? – Andy Wilkinson Dec 19 '19 at 18:18

2 Answers2

0

without more information, I would say your custom spring-boot-starter has not the same namespace, so the components are not scanned from your internal Application.

Lets say your internal Project namespace is: com.hello.package.p1 and your Spring-boot-starter has the namespace: net.greeting.package.p1

Try perhaps something like this:

@SpringBootTest(classes = TestConfiguration.class)

and in your TestConfiguration.class:

@Configuration
@ComponentScan(basePackages = "net.greeting.package.p1")
public static class TestConfiguration {

    // ...

}
Vladimir
  • 612
  • 3
  • 16
  • Thanks for your answer. As the spring boot starter aims to reduce the configuration from the projects using it, do you think that adding an explicit component scan around the starter package is the best solution? If yes, what's the gain versus a simple maven module? – Katy Dec 19 '19 at 13:47
0

Thanks for your answer.

When executing the internal project normally, I see clearly that they are getting the bean instances without the need to add any custom component scan. We have just added the custom starter to their dependencies. I don't see why it's not loaded while integration test. (I think that it should be reported to Spring community)

I have found a workaround which I consider not the best solution, by importing the CommonAutoConfiguration class to the internal project integration class.

@RunWith(SpringRunner.class)
@SpringBootTest(classes = { InternalProjectbootApplication.class })
@DataMongoTest(excludeAutoConfiguration = EmbeddedMongoAutoConfiguration.class)
@Import(CommonAutoConfiguration.class)
public class ArchiveUnitServiceITTest implements ServiceInterfaceIT {...
Katy
  • 1,023
  • 7
  • 19