服务器上部署Struts2的web项目报struts-default.xml:131:154的解决方法

背景:

用学生特价买了阿里云的服务器一年,为了练手,开始把毕业设计项目部署到该服务器上去。

项目使用的技术:Struts2

服务器上用tomcat启动该项目。

 

问题:

在楼主本地启动tomcat成功,tomcat能成功访问,项目地址也能成功访问。

在服务器上启动tomcat成功,tomcat能成功访问,但是项目地址访问报错。于是查看服务器上tomcat目录下/logs/catalina.out,发现报错如下:

 1 ERROR Dispatcher Dispatcher initialization failed
 2  Unable to load configuration. - bean - jar:file:/root/tomcat123/apache-tomcat-8.0.15/webapps/study/WEB-INF/lib/struts2-core-2.5.20.jar!/struts-default.xml:131:154
 3     at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
 4     at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:957)
 5     at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:463)
 6     at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:496)
 7     at org.apache.struts2.dispatcher.InitOperations.initDispatcher(InitOperations.java:73)
 8     at org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:61)
 9     at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
10     at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
11     at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
12     at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4615)
13     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5222)
14     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
15     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
16     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
17     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
18     at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:917)
19     at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1701)
20     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
21     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
22     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
23     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
24     at java.lang.Thread.run(Thread.java:748)
25 Caused by: Unable to load bean: type:com.opensymphony.xwork2.TextProviderFactory class:com.opensymphony.xwork2.StrutsTextProviderFactory - bean - jar:file:/root/tomcat123/apache-tomcat-8.0.15/webapps/study/WEB-INF/lib/struts2-core-2.5.20.jar!/struts-default.xml:131:154
26     at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:245)
27     at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:98)
28     at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:234)
29     at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
30     ... 21 more
31 Caused by: java.lang.IncompatibleClassChangeError: Implementing class
32     at java.lang.ClassLoader.defineClass1(Native Method)
33     at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
34     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
35     at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2452)
36     at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:854)
37     at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1264)
38     at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1147)
39     at com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:144)
40     at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:216)
41     ... 24 more

 

网上到处搜索"Dispatcher initialization failed",然而没有解决,又搜索"Unable to load configuration",还是没有解决。
于是想着自己再认真看一遍错误日志,感觉关键点在于"struts-default.xml:131:154"
赶紧打开该文件,截图如下:

服务器上部署Struts2的web项目报struts-default.xml:131:154的解决方法

然后又网上找资料,有人说是包重复的问题,我只能自己检查了,第131行,class="com.opensymphony.xwork2.StrutsTextProviderFactory",于是赶紧查看我引入的包中该class是否存在,然后发现问题:Struts2-core中有这个class,xwork-core中也有该class

查询了一下,Struts2-core是基于xwork-core开发的。

 

我的解决方案:

删除项目中引入的的xwork-core(可以在删除前备份一下,万一不行呢)

重启tomcat后,项目能正常访问。

 

ps:至于本地启动为什么没报错,我也不知,,,估计是环境的问题了

上一篇:AcWing 154. 滑动窗口(模板)


下一篇:SERE0014: Illegal HTML character: decimal 154