灰熊队球衣突然要 applicatonContext.xml
Grizzly Jersey suddenly asks for applicatonContext.xml
在我现有的应用程序中,这段代码工作正常:
GrizzlyHttpServer grizzlyHttpServer = new GrizzlyHttpServer(new Host("localhost", 80));
但是,如果我将其更改为使用 Grizzly Jersey 类路径中的代码来处理 JAX-RS 内容:
ResourceConfig resourceConfig = new ResourceConfig();
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(
URI.create("http://localhost:80/rest"),
resourceConfig,
false
);
grizzlyHttpServer = new GrizzlyHttpServer(httpServer, new Host("localhost", 80));
然后 createHttpServer() 方法中止
Caused by: java.io.FileNotFoundException: class path resource
[applicationContext.xml] cannot be opened because it does not exist
我没有告诉它使用 Spring。这里发生了什么魔法?
这是完整的堆栈跟踪:
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.access0(ApplicationHandler.java:163)
at
org.glassfish.jersey.server.ApplicationHandler.run(ApplicationHandler.java:323)
at org.glassfish.jersey.internal.Errors.call(Errors.java:289) at
org.glassfish.jersey.internal.Errors.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
正如人们所猜测的那样,添加一个空的虚拟 applicatonContext.xml 可以解决问题:
<?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>
这对我来说太神奇了。我会留下这个问题。
用户 peeskillet 找到了答案。
我有这个 Maven 依赖项
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
</dependency>
可能来自示例中的复制粘贴依赖项。我确实使用 Spring,但我自己处理 DI。我的项目已经具有所有 Spring 和其他依赖项。
只需删除此依赖项即可解决问题。
解释是new GrizzlyHttpServer()
是纯Grizzly代码,而GrizzlyHttpServerFactory.createHttpServer()
是grizzly jersey项目的代码。所以同时拥有
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
并且前面提到的 jersey-spring3
导致了所描述的行为。
在我现有的应用程序中,这段代码工作正常:
GrizzlyHttpServer grizzlyHttpServer = new GrizzlyHttpServer(new Host("localhost", 80));
但是,如果我将其更改为使用 Grizzly Jersey 类路径中的代码来处理 JAX-RS 内容:
ResourceConfig resourceConfig = new ResourceConfig();
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(
URI.create("http://localhost:80/rest"),
resourceConfig,
false
);
grizzlyHttpServer = new GrizzlyHttpServer(httpServer, new Host("localhost", 80));
然后 createHttpServer() 方法中止
Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
我没有告诉它使用 Spring。这里发生了什么魔法?
这是完整的堆栈跟踪:
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.access0(ApplicationHandler.java:163) at org.glassfish.jersey.server.ApplicationHandler.run(ApplicationHandler.java:323) at org.glassfish.jersey.internal.Errors.call(Errors.java:289) at org.glassfish.jersey.internal.Errors.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
正如人们所猜测的那样,添加一个空的虚拟 applicatonContext.xml 可以解决问题:
<?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>
这对我来说太神奇了。我会留下这个问题。
用户 peeskillet 找到了答案。
我有这个 Maven 依赖项
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
</dependency>
可能来自示例中的复制粘贴依赖项。我确实使用 Spring,但我自己处理 DI。我的项目已经具有所有 Spring 和其他依赖项。
只需删除此依赖项即可解决问题。
解释是new GrizzlyHttpServer()
是纯Grizzly代码,而GrizzlyHttpServerFactory.createHttpServer()
是grizzly jersey项目的代码。所以同时拥有
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
并且前面提到的 jersey-spring3
导致了所描述的行为。