异常启动过滤器 struts2 - 尝试添加 JAR,但结果相同

2022-01-16 00:00:00 java struts2 web.xml requestdispatcher

这是我得到的错误:

SEVERE: Exception starting filter struts2
java.lang.NoClassDefFoundError: com/opensymphony/xwork2/config/FileManagerProvider
    at org.apache.struts2.dispatcher.Dispatcher.init_FileManager(Dispatcher.java:336)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:465)
    at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:193)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:424)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4072)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4726)
    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:1317)
    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:1065)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    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(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.ClassNotFoundException: com.opensymphony.xwork2.config.FileManagerProvider
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    ... 30 more

JAR 列表:

antlr-2.7.6.jar
commons-beanutils-1.8.3.jar
commons-collections-3.2.1.jar
commons-digester-2.1.jar
commons-fileupload-1.3.jar
commons-logging-1.1.1.jar
dom4j-1.6.1.jar
ejb3-persistence-1.0.2.GA.jar
freemarker-2.3.16.jar
hibernate-annotations-3.2.1.ga.jar
hibernate-commons-annotations-3.3.0.ga.jar
hibernate-core-4.2.1.Final.jar
hsqldb-2.0.0.jar
javassist-3.12.1.GA.jar
jta-1.1.jar
log4j-1.2.15.jar
mysql-connector-java-5.1.21.jar
ognl-2.7.3.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.7.5.jar
struts2-core-2.3.14.3.jar
xwork-2.1.3.jar

而我的 web.xml 是这样的:

And my web.xml is like this:

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

在这个论坛上阅读后我尝试了很多东西:

I have tried lot of things after reading on this forum:

  1. 尝试了不同版本的 JAR.
  2. 手动将 WAR 部署到 Tomcat 中.
  3. 将 servlet-api JAR 也放入 lib 文件夹中(尽管它存在于服务器 lib 中).
  4. 阅读 Tomcat 日志,没有发现任何不同.(请告诉我,我也可以粘贴)

但他们都没有帮助.所以,万不得已,我把它贴在这里.

But none of them have helped. So, last resort, I am posting it here.

推荐答案

由于您使用的是 Struts 2.3,

Since you are using Struts 2.3,

FilterDispatcher 已弃用.您必须使用 StrutsPrepareAndExecuteFilter(或其小兄弟).

FilterDispatcher is deprecated. You MUST use StrutsPrepareAndExecuteFilter (or its little brothers).

来自官方文档

已弃用.从 Struts 2.1.3 开始,使用 StrutsPrepareAndExecuteFilter 或 StrutsPrepareFilter 和 StrutsExecuteFilter 如果需要在此之外使用 ActionContextCleanUp 过滤器em>

Deprecated. Since Struts 2.1.3, use StrutsPrepareAndExecuteFilter instead or StrutsPrepareFilter and StrutsExecuteFilter if needing using the ActionContextCleanUp filter in addition to this one

然后改这个

<!-- Struts < 2.1.3 -->
<filter-class>
    org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>

到这里:

<!-- Struts >= 2.1.3 and < 2.5 -->
<filter-class>
     org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>

请注意,从 2.5 开始,它将改为:

Note that, from 2.5, it would be instead:

<!-- Struts >= 2.5 -->
<filter-class>
     org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
</filter-class>

相关文章