背景: 在进行Spring Struts2 Hibernate 即SSH整合的过程中遇到了这个错误!
原因分析: Bean已经被加载了,不能重复加载
原来是Jar包重复了!
情形一: Tomcat的lib下加了jar包,项目的lib中又加入一遍jar包,形成冲突!
情形二: 导入了两个jar包, 功能相同. 一个带版本号,一个不带版本号.
所以 它竟然就去执行了两次, 无语! 它就不能偷偷懒, 只执行其中一个吗? 真的是
Caused by: com.opensymphony.xwork2.config.ConfigurationException: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:274) ~[struts2-core-2.5.20.jar:2.5.20]
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:98) ~[struts2-core-2.5.20.jar:2.5.20]
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:167) ~[struts2-core-2.5.20.jar:2.5.20]
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66) ~[struts2-core-2.5.20.jar:2.5.20]
... 53 more
Caused by: com.opensymphony.xwork2.config.ConfigurationException: Bean type class com.opensymphony.xwork2.ObjectFactory with the name struts has already been loaded by bean
- jar:file:/C:/Users/James/IdeaProjects/ssh_186/out/artifacts/web_war_exploded/WEB-INF/lib/struts2-core-2.5.20.jar!/struts-default.xml:69:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:260) ~[struts2-core-2.5.20.jar:2.5.20]
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:98) ~[struts2-core-2.5.20.jar:2.5.20]
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:167) ~[struts2-core-2.5.20.jar:2.5.20]
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66) ~[struts2-core-2.5.20.jar:2.5.20]
... 53 more
解决方法: 去掉其中一个Jar包就好了, 问题解决!
参考文章: https://blog.51cto.com/quietboy/1409337