I have 2 Maven projects:
- project1 that contains my entities/services/DAOs, with a Java Spring (4.2.4) config (no XML)
- project2 that is my RESTful API using Jersey (2.22.1), that contains the resources (controllers), Java configuration (extending
ResourceConfig
, no web.xml)
I would like to inject my services in my Jersey resources, here is what I did:
- I added the Maven dependency to project1 in project2
- I added the dependency jersey-spring3 to project2
I didn't change anything in my Jersey config class.
I run jetty (Maven plugin, no public static void main
or any class to run the server).
First attempt: applicationContext.xml was required.
Second attempt: after adding an empty applicationContext.xml (to project2), my services are not found.
Third attempt: after adding <context:component-scan base-package="com.xxx.project1"/>
to applicationContext.xml (package where my project1 Java Spring config lives), services are injected.
My question is how to get rid of the applicationContext.xml file?
I would like my Spring config from project1 to be detected automatically...
Some code:
The Spring configuration
@Configuration
@ComponentScan("com.xxx.project1.service")
public class SpringConfig {
}
The Jersey configuration
@ApplicationPath("/v1")
public class Application extends ResourceConfig {
public Application() {
packages("com.xxx.project2.filter",
"com.xxx.project2.resource");
register(RolesAllowedDynamicFeature.class);
}
}