Reputation: 11
I have an eclipse java project and under /src/main/java (package com.xxx.yyy). I also have a few Test classes under the /src/test/java (under package com.xxx.yyy). The test class (which is annotated as @Service(value = "sampleclient") public class SampleClient { ... } gets invoked by a framework code located in one of the packages under /src/main/java.
The component scan works fine if all the files/packages are under the /src/main/java. But it ignores the packages I have under /src/test/java.
How do I force spring to scan for components (packages) under multiple directories ?
Upvotes: 1
Views: 914
Reputation: 546
<context:component-scan base-package="x.y.z.prod.service, x.y.z.test.service" />
Upvotes: 0
Reputation: 2939
I would recommend you to use either maven or gradle build system which has clear demarcation between source and test code and how it has to be used in build life cycle. That means you will be able to use any test classes while "test" phase and ignore after that. You can also manage test dependencies accordingly.
Upvotes: 1