When starting an embedded Grizzly server, I would like Jersey to use my existing Spring container. This was possible in jersey-1.0 (Grizzly, sharing spring generated context), but does not seem to work in Jersey 2.x.
This code works in Jersey 1.17:
HttpServer server = new HttpServer();
final NetworkListener listener = new NetworkListener("grizzly", NetworkListener.DEFAULT_NETWORK_HOST, PACS.RESTPort);
listener.setSecure(false);
server.addListener(listener);
ResourceConfig rc = new PackagesResourceConfig("edu.mayo.qia.pacs.rest");
// Let Jersey know about our existing context
SpringComponentProviderFactory handler = new SpringComponentProviderFactory(rc, PACS.context);
HttpHandler processor = ContainerFactory.createContainer(HttpHandler.class, rc, handler);
server.getServerConfiguration().addHttpHandler(processor, "");
server.start();
Here is my code in Jersey 2 (I can't figure out a replacement for SpringComponentProviderFactory):
HttpServer server = new HttpServer();
final NetworkListener listener = new NetworkListener("grizzly", NetworkListener.DEFAULT_NETWORK_HOST, PACS.RESTPort);
server.addListener(listener);
ResourceConfig rc = new ResourceConfig();
rc.packages("edu.mayo.qia.pacs.rest");
HttpHandler processor = ContainerFactory.createContainer(GrizzlyHttpContainer.class, rc);
server.getServerConfiguration().addHttpHandler(processor, "");
When I run the code (with jersey-spring3), I get this exception:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException:
IOException parsing XML document from class path resource [applicationContext.xml];
nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
Grizzly is trying to load my Spring context from applicationContext.xml, but it is annotation based and already loaded. How can I get Grizzly and/or Jersey to find my context?
IVY Config is:
<dependency org="org.glassfish.jersey.core" name="jersey-client" rev="2.3"/>
<dependency org="org.glassfish.jersey.core" name="jersey-server" rev="2.3"/>
<dependency org="org.glassfish.jersey.core" name="jersey-common" rev="2.3"/>
<dependency org="org.glassfish.jersey.connectors" name="jersey-grizzly-connector" rev="2.3"/>
<dependency org="org.glassfish.jersey.containers" name="jersey-container-grizzly2-http" rev="2.3"/>
<dependency org="org.glassfish.jersey.ext" name="jersey-spring3" rev="2.3"/>