通过 Cargo 在嵌入式 Jetty 中调用 ehcache-server 时出现异常:无法实例化 WebApplicationProviderImpl
我正在开发一个 Web 应用程序,它使用独立的 ehcache 服务器来缓存某些数据。 ehcache 服务器通过 REST(而不是 SOAP)访问。
出于功能测试的目的,我需要运行 ehcache 服务器的嵌入式实例。 echcache-server 项目本身使用 Cargo Maven2 插件来进行自己的功能测试。 我尝试在应用程序的 pom.xml 中执行相同的操作,但 Cargo 插件坚持部署我自己的 Web 应用程序的 WAR,即使我将其配置为使用 ehcache 的 WAR 也是如此。
因此,我尝试直接使用 Cargo Container API 来进行部署和容器实例化。 下面是相关代码:
String localRepositoryPath = "/home/zoltan/.m2/repository";
String jettyHomeDirectory = "/tmp/cargoJettyHome";
LocalConfiguration configuration = new Jetty6xEmbeddedStandaloneLocalConfiguration(jettyHomeDirectory);
Deployable war = new WAR(localRepositoryPath + "/net/sf/ehcache/ehcache-server/0.7/ehcache-server-0.7.war");
configuration.addDeployable(war);
EmbeddedLocalContainer container = new Jetty6xEmbeddedLocalContainer(configuration);
container.start();
Jetty 容器启动,并且 ehcache 本身似乎部分启动,基于各种消息,这些消息看起来与启动独立服务器时生成的消息相同。 但是,RESTful Web 服务无法启动,并出现以下异常:
com.sun.jersey.spi.service.ServiceConfigurationError: com.sun.jersey.spi.container.WebApplicationProvider: The class com.sun.jersey.impl.container.WebApplicationProviderImpl implementing provider interface com.sun.jersey.spi.container.WebApplicationProvider could not be instantiated: null
at com.sun.jersey.spi.service.ServiceFinder.fail(ServiceFinder.java:346)
at com.sun.jersey.spi.service.ServiceFinder.access$600(ServiceFinder.java:144)
at com.sun.jersey.spi.service.ServiceFinder$LazyObjectIterator.hasNext(ServiceFinder.java:638)
at com.sun.jersey.spi.container.WebApplicationFactory.createWebApplication(WebApplicationFactory.java:61)
at com.sun.jersey.spi.container.servlet.ServletContainer.create(ServletContainer.java:570)
at com.sun.jersey.spi.container.servlet.ServletContainer.load(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:207)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:616)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:222)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.cargo.container.jetty.internal.JettyExecutorThread.run(JettyExecutorThread.java:68)
Caused by: java.lang.ClassCastException
at java.lang.Class.cast(Class.java:2990)
at com.sun.jersey.spi.service.ServiceFinder$LazyObjectIterator.hasNext(ServiceFinder.java:596)
... 26 more
以下是我的 pom.xml 中的相关依赖项:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-spring</artifactId>
<version>1.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-servlet-tester</artifactId>
<version>6.1.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-core-api-container</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-core-api-generic</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-core-container-jetty</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-server</artifactId>
<version>0.7</version>
<type>war</type>
</dependency>
有谁知道什么可能会导致此异常? 也许我使用的 jetty 和 jersey 版本不匹配? 我是否必须以某种方式注册 WebApplicationProviderImpl? 任何想法将不胜感激。
I'm working on a web application that uses a standalone ehcache server to cache certain data. The ehcache server is accessed via REST (as opposed to SOAP).
For functional testing purposes, I need to run an embedded instance of the ehcache server. The echcache-server project itself does this for its own functional tests, using the Cargo Maven2 plugin. I tried doing the same thing in my application's pom.xml, but the Cargo plugin insists on deploying my own web application's WAR, even when I configure it to use ehcache's WAR instead.
Therefore, I am trying to use the Cargo Container API directly to do the deployment and container instantiation. Here is the relevant code:
String localRepositoryPath = "/home/zoltan/.m2/repository";
String jettyHomeDirectory = "/tmp/cargoJettyHome";
LocalConfiguration configuration = new Jetty6xEmbeddedStandaloneLocalConfiguration(jettyHomeDirectory);
Deployable war = new WAR(localRepositoryPath + "/net/sf/ehcache/ehcache-server/0.7/ehcache-server-0.7.war");
configuration.addDeployable(war);
EmbeddedLocalContainer container = new Jetty6xEmbeddedLocalContainer(configuration);
container.start();
The Jetty container starts, and ehcache itself seems to partially start, based on various messages that look the same as what is generated when starting the standalone server. However, the RESTful web service fails to start, with the following exception:
com.sun.jersey.spi.service.ServiceConfigurationError: com.sun.jersey.spi.container.WebApplicationProvider: The class com.sun.jersey.impl.container.WebApplicationProviderImpl implementing provider interface com.sun.jersey.spi.container.WebApplicationProvider could not be instantiated: null
at com.sun.jersey.spi.service.ServiceFinder.fail(ServiceFinder.java:346)
at com.sun.jersey.spi.service.ServiceFinder.access$600(ServiceFinder.java:144)
at com.sun.jersey.spi.service.ServiceFinder$LazyObjectIterator.hasNext(ServiceFinder.java:638)
at com.sun.jersey.spi.container.WebApplicationFactory.createWebApplication(WebApplicationFactory.java:61)
at com.sun.jersey.spi.container.servlet.ServletContainer.create(ServletContainer.java:570)
at com.sun.jersey.spi.container.servlet.ServletContainer.load(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:207)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:616)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:222)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.cargo.container.jetty.internal.JettyExecutorThread.run(JettyExecutorThread.java:68)
Caused by: java.lang.ClassCastException
at java.lang.Class.cast(Class.java:2990)
at com.sun.jersey.spi.service.ServiceFinder$LazyObjectIterator.hasNext(ServiceFinder.java:596)
... 26 more
Here are the relevant dependencies from my pom.xml:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-spring</artifactId>
<version>1.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-servlet-tester</artifactId>
<version>6.1.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-core-api-container</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-core-api-generic</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-core-container-jetty</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-server</artifactId>
<version>0.7</version>
<type>war</type>
</dependency>
Does anyone know what might cause this exception? Perhaps I'm using mismatched versions of jetty and jersey? Do I have to somehow register a WebApplicationProviderImpl? Any ideas would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有解决方案:相反,我的功能测试使用独立的 ehcache 服务器。
ehcache 邮件列表中的某人建议了另一种方法。
I don't have a solution to this: instead, my functional tests are using a standalone ehcache server.
Someone on the ehcache mailing list suggested an alternative approach.