从 Struts 2.3.37 迁移到 Struts 2.5.33。 我已经参考了下面给出的页面 https://cwiki.apache.org/confluence/display/WW/Struts+2.3+to+2.5+migration 我在 Tomcat (v9.0.45) 上运行时遇到错误
SEVERE: Exception sending context initialized event to listener instance of class [org.apache.struts2.tiles.StrutsTilesListener]
java.lang.NoSuchMethodError: org.apache.tiles.impl.BasicTilesContainer.setApplicationContext(Lorg/apache/tiles/request/ApplicationContext;)V
at org.apache.tiles.factory.BasicTilesContainerFactory.createContainer(BasicTilesContainerFactory.java:84)
at org.apache.tiles.startup.AbstractTilesInitializer.createContainer(AbstractTilesInitializer.java:114)
at org.apache.tiles.startup.AbstractTilesInitializer.initialize(AbstractTilesInitializer.java:64)
at org.apache.tiles.web.startup.AbstractTilesListener.contextInitialized(AbstractTilesListener.java:53)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4716)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5172)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:843)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:433)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:772)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:342)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:473)
我已参考上面给出的链接。
错误是
java.lang.NoSuchMethodError:org.apache.tiles.impl.BasicTilesContainer.setApplicationContext(Lorg/apache/tiles/request/ApplicationContext;)V
因为类路径上的某个地方有旧的图块库。可能您已将它们打包到
WEB-INF/lib
文件夹中。可能是 Tiles 2.2。在您发布的链接中写着:
根据您升级的struts版本以及您使用的是tiles-plugin还是tiles3-plugin,您可能需要执行不同的步骤。
Struts 2.5只提供了一个使用Tiles3的tiles插件。因此,对 Tiles2 以及tiles3-plugin 名称的支持已被删除。
现在唯一的 Maven 依赖项看起来像这样
tiles 插件的 Maven 依赖:
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-tiles-plugin</artifactId> <version>${struts2.version}></version> </dependency>
您可能需要将tiles.xml文件中的DTD更新为Tiles3:
tiles3.dtd:
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
需要 web.xml 中的监听器。无需在此处配置tiles.xml文件的路径,因为它们是自动拾取的。
web.xml 中的StrutsTilesListener:
<listener> <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class> </listener>
您可以选择从 XML 中删除 TilesDefinitions 并改为注释操作。请参阅Tiles 插件了解更多详细信息。