I have spring boot application sample with package layout:
main:
-com.foo
Application.java
-com.foo.services
ItemService.java
ItemRepository.java
-com.foo.config
Configuration.java
test:
-com.foo.services
ItemServiceIngegrationTest.java
My integration test fails to run being not able to find ItemRepository bean if put
@ComponentScan(basePackageClasses = { ItemService.class })
but works if I put
@ComponentScan(basePackageClasses = { Application.class })
where is the trick ?
spec says :
Either basePackageClasses() or basePackages() (or its alias value()) may be specified to define specific packages to scan. If specific packages are not defined, scanning will occur from the package of the class that declares this annotation.
@EnableAutoConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { Configuration.class })
public class ItemServiceIntegrationTest {
. . .
}
@org.springframework.context.annotation.Configuration
@PropertySource("classpath:application.properties")
@ComponentScan(basePackageClasses = { ItemService.class })
public class Configuration extends AbstractMongoConfiguration {
. . .
}