I have a spring boot application like this:
package my.package;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration;
@SpringBootApplication
public class MySpringBootApp{
public static void main(String[] args) {
SpringApplication.run(MySpringBootApp.class, args);
}
}
I have a service in the package my.package.service
@Service
public class MyService {
private ServiceInADifferentJar dep;
public MySerivce(ServiceInADifferentJar dep) {
this.dep = dep;
}
}
The class ServiceInADifferentJar
is an @Service
annotated class in a different JAR, which I include as a maven dependency.
The JAR Has this file structure:
src/main/java
- some.package.repository
MyRepository.java
- some.package.service
ServiceInADifferentJar.java
MyRepository
is an @Repository
annotated interface that extends a Spring Data inerface.
ServiceInADifferentJar
gets MyRepository
injected in its constructor.
WHen I start the application, I get an error that ServiceInADifferentJar
cannot be found.
Then I added this to my SpringBootApp
@SpringBootApplication(scanBasePackages = {"some.package"})
andServiceInADifferentJar
is found, but not MyRepository
.
Why not? Why aren't all sub-packages of some.package
in the other JAR scanned?
* EDIT *
The repository
package some.package.repository;
@Repository
public interface MyRepository extends MongoRepository<SomeEntity, String> {
}