struts2部署问题:找不到自定义struts-default.xml文件

struts2-core-2.3.15.3包中默认存在一个struts-default.xml文件。包含struts默认配置。

由于要在默认拦截器中加入设置,默认配置不能满足需求。所以自定义了一个struts-default.xml文件叫做(struts-default-my.xml文件)。

在struts.xml文件中该文件,启动服务后提示如下异常信息:

严重: Dispatcher initialization failed
Unable to load configuration. - bean - file:/G:/apache-tomcat-6.0.13/webapps/strutsExample/WEB-INF/classes/struts-default-my.xml:29:72
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
	at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446)
	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490)
	at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:193)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
	at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
	at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:108)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3693)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4340)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
	at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
	at org.apache.catalina.core.StandardService.start(StandardService.java:516)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - file:/G:/apache-tomcat-6.0.13/webapps/strutsExample/WEB-INF/classes/struts-default-my.xml:29:72
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:245)
	at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102)
	at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:226)
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
	... 30 more
Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by [unknown location] - bean - file:/G:/apache-tomcat-6.0.13/webapps/strutsExample/WEB-INF/classes/struts-default-my.xml:29:72
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:229)
	... 33 more
2013-12-24 15:16:42 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
Unable to load configuration. - bean - file:/G:/apache-tomcat-6.0.13/webapps/strutsExample/WEB-INF/classes/struts-default-my.xml:29:72
	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:502)
	at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:193)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
	at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
	at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:108)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3693)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4340)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
	at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
	at org.apache.catalina.core.StandardService.start(StandardService.java:516)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: Unable to load configuration. - bean - file:/G:/apache-tomcat-6.0.13/webapps/strutsExample/WEB-INF/classes/struts-default-my.xml:29:72
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
	at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446)
	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490)
	... 28 more
Caused by: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - file:/G:/apache-tomcat-6.0.13/webapps/strutsExample/WEB-INF/classes/struts-default-my.xml:29:72
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:245)
	at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102)
	at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:226)
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
	... 30 more
Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by [unknown location] - bean - file:/G:/apache-tomcat-6.0.13/webapps/strutsExample/WEB-INF/classes/struts-default-my.xml:29:72
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:229)
	... 33 more
2013-12-24 15:16:42 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2013-12-24 15:16:42 org.apache.catalina.core.StandardContext start
严重: Context [/strutsExample] startup failed due to previous errors

关键在于找不到自定义配置文件:

Unable to load configuration. - bean - file:/G:/apache-tomcat-6.0.13/webapps/strutsExample/WEB-INF/classes/struts-default-my.xml:29:72
但根据目录可以找到文件。


分析后查明原因如下几点:

1.struts2-core-2.3.15.3包中存在的struts-default.xml文件在启动过程中已加载。

2.struts-default-my.xml文件中 与默认配置文件重名。

3.struts-default-my.xml文件中重复加载了默认文件中已经加载的bean文件,导致加载bean重名。


解决方法:修改2的重复名称,删除3的重复加载;



你可能感兴趣的:(struts2学习记录-问题)