我编写了一个简单的Web服务,用JAXB解析XML文件。这项服务在我“运行”时运作。它来自NetBeans(Tomcat 8.0.3)的菜单,但如果我将WAR文件放入tomcat的webapps文件夹并启动tomcat(两个服务器之间的server.xml相同),我会收到以下错误:
请帮助解决此问题:
01-Sep-2015 15:07:45.979 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
01-Sep-2015 15:07:46.006 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
01-Sep-2015 15:07:46.009 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8443"]
01-Sep-2015 15:07:46.277 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
01-Sep-2015 15:07:46.280 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
01-Sep-2015 15:07:46.283 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
01-Sep-2015 15:07:46.283 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 824 ms
01-Sep-2015 15:07:46.330 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
01-Sep-2015 15:07:46.330 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.5
01-Sep-2015 15:07:46.356 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive C:\apache-tomcat-8.0.5-windows-x64\apache-tomcat-8.0.5\webapps\k4kReadOrderService.war
01-Sep-2015 15:07:46.372 WARNING [localhost-startStop-1] org.apache.catalina.startup.SetContextPropertiesRule.begin [SetContextPropertiesRule]{Context} Setting property 'antiJARLocking' to 'true' did not find a matching property.
01-Sep-2015 15:07:46.972 SEVERE [localhost-startStop-1] org.apache.catalina.startup.ContextConfig.processServletContainerInitializers Failed to process JAR found at URL [/k4kReadOrderService] for ServletContainerInitializers for context with name [{1}]
java.io.IOException: java.lang.ClassCastException: Cannot cast org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer to javax.servlet.ServletContainerInitializer
at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:185)
at org.apache.catalina.startup.WebappServiceLoader.load(WebappServiceLoader.java:151)
at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1597)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1125)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:768)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:303)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5058)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:697)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:976)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1762)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: Cannot cast org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer to javax.servlet.ServletContainerInitializer
at java.lang.Class.cast(Unknown Source)
at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:182)
... 19 more
01-Sep-2015 15:07:47.006 SEVERE [localhost-startStop-1] org.apache.catalina.startup.ContextConfig.configureStart Marking this application unavailable due to previous error(s)
01-Sep-2015 15:07:47.015 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Error getConfigured
01-Sep-2015 15:07:47.017 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [/k4kReadOrderService] startup failed due to previous errors
01-Sep-2015 15:07:47.027 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.0.5-windows-x64\apache-tomcat-8.0.5\webapps\docs
01-Sep-2015 15:07:47.142 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.0.5-windows-x64\apache-tomcat-8.0.5\webapps\examples
01-Sep-2015 15:07:47.604 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.0.5-windows-x64\apache-tomcat-8.0.5\webapps\host-manager
01-Sep-2015 15:07:47.647 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.0.5-windows-x64\apache-tomcat-8.0.5\webapps\manager
01-Sep-2015 15:07:47.698 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.0.5-windows-x64\apache-tomcat-8.0.5\webapps\ROOT
01-Sep-2015 15:07:47.726 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
01-Sep-2015 15:07:47.732 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8443"]
01-Sep-2015 15:07:47.734 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
01-Sep-2015 15:07:47.736 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1452 ms
答案 0 :(得分:0)
检查您的 servlet-api 是否包含多次:
mvn dependency:tree -Dverbose
如果是这样,您可以使用其中一个过渡依赖项(例如我修复同一问题的例子)排除过渡依赖项:
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jetty</artifactId>
<version>2.23.2</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>