Reputation: 1764
In my existing app this code works fine:
GrizzlyHttpServer grizzlyHttpServer = new GrizzlyHttpServer(new Host("localhost", 80));
However, if I change it to use code from the Grizzly Jersey classpath for JAX-RS stuff:
ResourceConfig resourceConfig = new ResourceConfig();
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(
URI.create("http://localhost:80/rest"),
resourceConfig,
false
);
grizzlyHttpServer = new GrizzlyHttpServer(httpServer, new Host("localhost", 80));
Then on the createHttpServer() method is aborts with
Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
I don't tell it to use Spring. What magic is going on here?
Here's the full stack trace:
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 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93) at org.glassfish.jersey.server.spring.SpringComponentProvider.createXmlSpringConfiguration(SpringComponentProvider.java:164) at org.glassfish.jersey.server.spring.SpringComponentProvider.createSpringContext(SpringComponentProvider.java:155) at org.glassfish.jersey.server.spring.SpringComponentProvider.initialize(SpringComponentProvider.java:98) at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:430) at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:163) at org.glassfish.jersey.server.ApplicationHandler$3.run(ApplicationHandler.java:323) at org.glassfish.jersey.internal.Errors$2.call(Errors.java:289) at org.glassfish.jersey.internal.Errors$2.call(Errors.java:286) at org.glassfish.jersey.internal.Errors.process(Errors.java:315) at org.glassfish.jersey.internal.Errors.process(Errors.java:297) at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:286) at org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:320) at org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:285) at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.(GrizzlyHttpContainer.java:331) at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:141) at com.optimaize.soapworks.exampleproject.server.boot.GrizzlySoapWebServer.start(GrizzlySoapWebServer.java:39) at com.optimaize.soapworks.exampleproject.server.boot.Boot.boot(Boot.java:38) at com.optimaize.soapworks.exampleproject.server.boot.Boot.main(Boot.java:18) Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328) ... 30 more
Upvotes: 1
Views: 1235
Reputation: 1764
User peeskillet found the answer.
I have this Maven dependency
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
</dependency>
probably from copy-pasting dependencies from an example. I do use Spring, but I handle the DI myself. My project already has all the Spring and other dependencies.
Simply removing this dependency solves the case.
The explanation is that new GrizzlyHttpServer()
is pure Grizzly code, while GrizzlyHttpServerFactory.createHttpServer()
is code from the grizzly jersey project. So having both
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
And the aforementioned jersey-spring3
causes the behavior as described.
Upvotes: 1
Reputation: 1764
As one could guess, adding a dummy empty applicatonContext.xml makes the problem go away:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
This is too much magic for my taste. I'll leave the question open.
Upvotes: 1