背景: 在進行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