我正在开发一个使用独立 ehcache 服务器来缓存某些数据的 Web 应用程序。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>
有谁知道可能导致此异常的原因?也许我正在使用不匹配的码头和球衣版本?我是否必须以某种方式注册 WebApplicationProviderImpl?任何想法将不胜感激。