我正在尝试将项目迁移到 Maven 并声明 Struts 2 依赖项,但我遇到了这个错误。我已经仔细检查了
pom.xml
依赖项,确保 struts2-core
仅声明一次,添加了排除项等。我也尝试过使用和不使用 xwork-core
依赖,同样的错误。我真的被困住了,不知道如何继续。
我的错误:
15:35:29,079 INFO [com.opensymphony.xwork2.config.providers.XmlConfigurationProvider] (ServerService Thread Pool -- 72) Parsing configuration file [struts-default.xml]
15:35:29,124 ERROR [org.apache.struts2.dispatcher.Dispatcher] (ServerService Thread Pool -- 72) Dispatcher initialization failed: Unable to load configuration. - bean - vfs:/C:/servers/JBoss-eap-6.1/standalone/deployments/war.war/WEB-INF/lib/struts2-core-2.3.16.jar/struts-default.xml:40:72
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70) [xwork-core-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:445) [struts2-core-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:489) [struts2-core-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74) [struts2-core-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57) [struts2-core-2.3.16.3.jar:2.3.16.3]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:416) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3225) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3791) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156) [jboss-as-web-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60) [jboss-as-web-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93) [jboss-as-web-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [rt.jar:1.6.0_13]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [rt.jar:1.6.0_13]
at java.util.concurrent.FutureTask.run(FutureTask.java:138) [rt.jar:1.6.0_13]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_13]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_13]
at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_13]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - vfs:/C:/servers/JBoss-eap-6.1/standalone/deployments/war.war/WEB-INF/lib/struts2-core-2.3.16.jar/struts-default.xml:40:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:245) [xwork-core-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102) [struts2-core-2.3.16.3.jar:2.3.16.3]
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:234) [xwork-core-2.3.16.3.jar:2.3.16.3]
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67) [xwork-core-2.3.16.3.jar:2.3.16.3]
... 17 more
Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name struts has already been loaded by bean - vfs:/C:/servers/JBoss-eap-6.1/standalone/deployments/war.war/WEB-INF/lib/struts2-core-2.3.16.3.jar/struts-default.xml:40:72 - bean - vfs:/C:/servers/JBoss-eap-6.1/standalone/deployments/war.war/WEB-INF/lib/struts2-core-2.3.16.jar/struts-default.xml:40:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:229) [xwork-core-2.3.16.3.jar:2.3.16.3]
... 20 more
15:35:29,134 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/fordaq]] (ServerService Thread Pool -- 72) JBWEB000284: Exception starting filter struts: Unable to load configuration. - bean - vfs:/C:/servers/JBoss-eap-6.1/standalone/deployments/war.war/WEB-INF/lib/struts2-core-2.3.16.jar/struts-default.xml:40:72
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:501) [struts2-core-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74) [struts2-core-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57) [struts2-core-2.3.16.3.jar:2.3.16.3]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:416) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3225) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3791) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1]
at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156) [jboss-as-web-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60) [jboss-as-web-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93) [jboss-as-web-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [rt.jar:1.6.0_13]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [rt.jar:1.6.0_13]
at java.util.concurrent.FutureTask.run(FutureTask.java:138) [rt.jar:1.6.0_13]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_13]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_13]
at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_13]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: Unable to load configuration. - bean - vfs:/C:/servers/JBoss-eap-6.1/standalone/deployments/war.war/WEB-INF/lib/struts2-core-2.3.16.jar/struts-default.xml:40:72
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70) [xwork-core-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:445) [struts2-core-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:489) [struts2-core-2.3.16.3.jar:2.3.16.3]
... 15 more
Caused by: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - vfs:/C:/servers/JBoss-eap-6.1/standalone/deployments/war.war/WEB-INF/lib/struts2-core-2.3.16.jar/struts-default.xml:40:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:245) [xwork-core-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102) [struts2-core-2.3.16.3.jar:2.3.16.3]
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:234) [xwork-core-2.3.16.3.jar:2.3.16.3]
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67) [xwork-core-2.3.16.3.jar:2.3.16.3]
... 17 more
Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name struts has already been loaded by bean - vfs:/C:/servers/JBoss-eap-6.1/standalone/deployments/war.war/WEB-INF/lib/struts2-core-2.3.16.3.jar/struts-default.xml:40:72 - bean - vfs:/C:/servers/JBoss-eap-6.1/standalone/deployments/war.war/WEB-INF/lib/struts2-core-2.3.16.jar/struts-default.xml:40:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:229) [xwork-core-2.3.16.3.jar:2.3.16.3]
... 20 more
pom.xml
具有依赖项:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>2.3.16</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.3.16</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-struts1-plugin</artifactId>
<version>2.3.16</version>
<exclusions>
<exclusion>
<artifactId>struts2-core</artifactId>
<groupId>org.apache.struts</groupId>
</exclusion>
</exclusions>
</dependency>
首先您需要添加
struts2-core
工件并测试它是否有效,然后添加 Spring 和/或其他插件。了解如何使用 Maven 创建 Struts 2 Web 应用程序来管理工件并构建应用程序。
核心struts2应用程序的
pom.xml
仅需要
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>X.X.X.X</version>
</dependency>
其中
X.X.X.X
是具体版本,即 2.3.16.3
或 2.3.24.1
,
它将下载所有其他依赖项。使用插件与其他框架集成,并且不会弄乱重复的依赖项。清理、重建、重新部署。检查 WEB-INF/lib
它不应包含来自不同版本的重复库。在你的情况下
struts2-core-2.3.16.3.jar
和 struts2-core-2.3.16.jar
都加载到类路径上。这是错误的,两个不同版本不应该有同一个库。
您还使用其他插件
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>2.3.16.3</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.3.16.3</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-struts1-plugin</artifactId>
<version>2.3.16.3</version>
</dependency>
可以添加到
pom.xml
。