2011-04-20 49 views
3

我得到一個ClassCastException爲org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterMaven的負載Servlet API的兩次

在我看到我的javax.servlet.Filter被加載兩次日誌。

從我的本地倉庫

[Loaded javax.servlet.Filter from file:/C:/Users/xxxx/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar] 

而另一個

一旦從Tomcat

[Loaded javax.servlet.Filter from file:/C:/Apache.org/apache-tomcat-6.0.32/lib/servlet-api.jar] 

只要過濾器的第二個版本被加載,我得到的服務器日誌以下異常。

Apr 20, 2011 2:42:21 PM org.apache.catalina.core.StandardContext filterStart 
SEVERE: Exception starting filter struts2 
java.lang.ClassCastException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter cannot be cast to javax.servlet.Filter 
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275) 
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422) 
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115) 
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4071) 
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4725) 
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799) 
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779) 
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601) 
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675) 
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601) 
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502) 
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1315) 
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324) 
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142) 
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061) 
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840) 
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) 
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463) 
at org.apache.catalina.core.StandardService.start(StandardService.java:525) 
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754) 
at org.apache.catalina.startup.Catalina.start(Catalina.java:595) 
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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) 
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) 
Apr 20, 2011 2:42:21 PM org.apache.catalina.core.StandardContext start 
SEVERE: Error filterStart 

這裏是我的pom.xml

<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>servlet-api</artifactId> 
    <version>2.5</version> 
    <type>jar</type> 
    <scope>provided</scope> 
    <optional>false</optional> 
</dependency> 

謝謝你看一個片斷。

+0

您可以發佈您的pom.xml請 – 2011-04-20 20:34:38

回答

4

您應該將pom.xml中的servlet-api依賴項標記爲<scope>provided</scope>,以便maven不會將其包含在最終版本中。然後執行mvn clean package

+0

@fmucar我看到提供的範圍。任何其他想法? – pacman 2011-04-20 20:17:44

+0

它是否將servlet-api放入web-inf/lib的最終版本中?也許孩子pom覆蓋它 – fmucar 2011-04-20 20:23:52

+1

我的web-inf/lib中沒有任何內容,但是我在我的tomcat/lib – pacman 2011-04-20 20:33:44

4

嘗試清除tomcat臨時目錄中的所有爆炸戰爭。有時候垃圾會導致一個類的多個版本被加載。特別是如果你在過渡期間改變了你的pom.xml。這樣做,並將範圍保留爲provided