Skip to content
Advertisement

spring boot – integration test autowired interface no such bean found

I have a spring-boot app that now needs to support multiple Object stores and selectively use the desired store based on the environment. Essentially what i have done is create an interface that each store repository then implements.

I have simplified the code for the examples. I have created 2 beans for each store type based on the spring profile determining the env:

JavaScript

in the service layer I have autowired the interface and then in the repositories i have used @Profile to specify which instance of the interface to use.

JavaScript

When I start the application with the configured “env” this actually runs as expected. however when running the test I get the “no qualifying bean of type ObjectStore. expected at least 1 bean which qualifies as autowire candidate.”

JavaScript

As noted in the @ActiveProfile on the test class there are some other environments e.g. dev,test,prod. I have tried playing around with Component scan, having impl and interface in the same package, etc, to no success. I feel like I am missing something obvious with the test setup. But could be something with my overall application config? my main aim with the solution is to avoid having something a long the lines of

JavaScript

Advertisement

Answer

Try @ActiveProfiles({"env1", "test"}).

Activate multiple profiles using @ActiveProfiles and specify profiles as an array.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement