我使用com.sun.jersey.spi.spring.container.servlet.SpringServlet
创建了两个Jersey servlet项目。我用的是平针织物1.19.1罐子。这两个项目都有lib文件夹中的依赖jar。我在自由9服务器中部署了这两个项目
当我尝试访问端点时,一个项目工作正常但不是另一个项目。如果第二个项目不起作用,我在控制台中有以下异常。如果我单独重启该项目(而不是服务器),它就可以工作。我不知道为什么,我试图找到永久解决方案。
SRVE0271E:应用程序[secondproject]中servlet [jersey-servlet]创建的未捕获的init()异常:java.lang.RuntimeException:javax.naming.NameNotFoundException:CDIExtension
SRVE0315E:发生异常:java.lang.Throwable:javax.servlet.ServletException:SRVE0207E:servlet创建的未捕获初始化异常
如果第一个项目不起作用,我会在控制台中看到以下异常。
SRVE0271E:应用程序[firstproject]中servlet [jersey-servlet]创建的未捕获的init()异常:java.lang.ClassCastException:com.sun.jersey.server.impl.cdi.CDIExtension与com.sun.jersey不兼容.server.impl.cdi.CDIExtension
SRVE0276E:初始化Servlet时出错[jersey-servlet]:javax.servlet.ServletException:SRVE0207E:servlet创建的未捕获初始化异常
使用完整堆栈更新:
java.lang.RuntimeException: javax.naming.NameNotFoundException: CDIExtension
at com.sun.jersey.server.impl.cdi.CDIExtension.getInitializedExtension(CDIExtension.java:183)
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactory.<init>(CDIComponentProviderFactory.java:95)
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer.initialize(CDIComponentProviderFactoryInitializer.java:76)
at com.sun.jersey.spi.container.servlet.WebComponent.configure(WebComponent.java:572)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.configure(ServletContainer.java:332)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:604)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:332)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.loadOnStartupCheck(ServletWrapper.java:1428)
at com.ibm.ws.webcontainer.webapp.WebApp.doLoadOnStartupActions(WebApp.java:1181)
at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinally(WebApp.java:1149)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:1055)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:6499)
at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApp(DynamicVirtualHost.java:446)
at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.createRunnableHandler(DynamicVirtualHost.java:248)
at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.createRunnableHandler(DynamicVirtualHost.java:313)
at com.ibm.ws.http.internal.VirtualHostImpl.discriminate(VirtualHostImpl.java:251)
at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.ready(HttpDispatcherLink.java:300)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:471)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleNewRequest(HttpInboundLink.java:405)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.processRequest(HttpInboundLink.java:285)
at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.ready(HttpInboundLink.java:256)
at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:174)
at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:83)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.requestComplete(WorkQueueManager.java:504)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.attemptIO(WorkQueueManager.java:574)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager.workerRun(WorkQueueManager.java:929)
at com.ibm.ws.tcpchannel.internal.WorkQueueManager$Worker.run(WorkQueueManager.java:1018)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.lang.Thread.run(Thread.java:785)
Caused by: javax.naming.NameNotFoundException: CDIExtension
at com.ibm.ws.jndi.internal.ContextNode.lookup(ContextNode.java:218)
at com.ibm.ws.jndi.internal.WSContext.lookup(WSContext.java:297)
at com.ibm.ws.jndi.WSContextBase.lookup(WSContextBase.java:62)
at com.sun.jersey.server.impl.cdi.CDIExtension.getInitializedExtension(CDIExtension.java:181)
... 33 more
Caused by: java.lang.ClassCastException: com.sun.jersey.server.impl.cdi.CDIExtension incompatible with com.sun.jersey.server.impl.cdi.CDIExtension
at com.sun.jersey.server.impl.cdi.CDIExtension.getInitializedExtension(CDIExtension.java:181)
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactory.<init>(CDIComponentProviderFactory.java:95)
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer.initialize(CDIComponentProviderFactoryInitializer.java:76)
at com.sun.jersey.spi.container.servlet.WebComponent.configure(WebComponent.java:572)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.configure(ServletContainer.java:332)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:604)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:332)
... 1 more
答案 0 :(得分:3)
请检查this link,这对我有帮助。
您可以在设置系统属性时解决问题
com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true
这可以从GlassFish服务器控制台完成。
添加新条目
-Dcom.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager =真
重启服务器
答案 1 :(得分:0)
在日志中,您可以看到:
Caused by: java.lang.ClassCastException: com.sun.jersey.server.impl.cdi.CDIExtension incompatible with com.sun.jersey.server.impl.cdi.CDIExtension
Liberty使用Jersey作为JAX-RS提供程序,因此您会遇到冲突。您必须从应用程序中删除这些jar,或者确保未在server.xml中显式或隐式包含JAX-RS功能
答案 2 :(得分:0)
错误
javax.naming.NameNotFoundException: Unable to resolve 'com.sun.jersey.config.CDIExtension'. Resolved 'com.sun.jersey.config'; remaining name 'CDIExtension'
可能是由于EJB3中的类导入引起的 示例:
import javax.enterprise.context.RequestScoped;
@RequestScoped
public class SampleServices {
@EJB
CalcBeanLocal calcBean;
.....
导入 RequestScope 时,“ bean.xml”将添加到WEB-INF。
可以通过使用 @stateless 注释而不是@RequestScope并通过在WEB-INF中删除上面创建的“ bean.xml”来解决此问题。
示例:
@stateless
public class SampleServices {
@EJB
CalcBeanLocal calcBean;
.....