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

时间:2023-01-12 05:46:28

背景:

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

项目使用的技术:Struts2

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

问题:

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

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

 ERROR Dispatcher Dispatcher initialization failed
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
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:957)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:463)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:496)
at org.apache.struts2.dispatcher.InitOperations.initDispatcher(InitOperations.java:73)
at org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:61)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4615)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5222)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:917)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1701)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
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
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:245)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:98)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:234)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
... 21 more
Caused by: java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2452)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:854)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1264)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1147)
at com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:144)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:216)
... 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:至于本地启动为什么没报错,我也不知,,,估计是环境的问题了