struts2 --web.xml-- Dispatcher initialization failed

信息: Parsing configuration file [struts.xml]
2011-9-17 17:39:59 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
严重: Dispatcher initialization failed
com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$Mis
singDependencyException: No mapping found for dependency [type=com.opensymphony.xwork2.ObjectFactory
, name='default'] in public void com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.s
etObjectFactory(com.opensymphony.xwork2.ObjectFactory).
	at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:144)
	at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMethods(ContainerImpl.java:113)
	at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:90)
	at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:86)
	at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:71)
	at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:67)
	at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76)
	at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)
	at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:483)
	at com.opensymphony.xwork2.inject.ContainerImpl$6.call(ContainerImpl.java:523)
	at com.opensymphony.xwork2.inject.ContainerImpl$6.call(ContainerImpl.java:521)
	at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:574)
	at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:521)
	at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.ja
va:203)
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:6
6)
	at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:380)
	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:424)
	at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
	at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecu
teFilter.java:51)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:273)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:254)
	at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:372)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:98)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4542)
	at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5220)
	at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5215)
	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found
 for dependency [type=com.opensymphony.xwork2.ObjectFactory, name='default'] in public void com.open
symphony.xwork2.config.providers.XmlConfigurationProvider.setObjectFactory(com.opensymphony.xwork2.O
bjectFactory).

 今天,在整struts2.2的项目时,启动时,出现以上错误。

查看web.xml文件,发现s2的配置如下:

                <filter>
		<filter-name>struts2</filter-name>
		<filter-class>
			org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
		 <init-param>
			<param-name>config</param-name>
			<param-value>struts.xml</param-value>
		</init-param> 
	</filter>

 研究了下,发现是param-name的应用文件时出现错,这样应用文件时,找不到strugs.xml文件。

于是乎,

 

解决办法一:

                              <init-param>
			<param-name>config</param-name>
			<param-value>classpath:struts.xml</param-value>
		</init-param>

 这段code注释掉,(注:struts.xml文件本身就在项目的源文件的根目录下)

再次启动项目:运行通过!

 

解决办法二:

 将init-param代码块改为如下代码:

                                <init-param>
			<param-name>config</param-name>
			<param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>
		</init-param>

 再次启动项目:运行通过!

 

法二的原因:

struts-default.xml,struts-plugin.xml 系统默认必需加上,后面写自己的struts.xml

位置 是从 WEB-INF 的 classes 开始计算


struts.xml 的路径为 WEB-INF/class/struts.xml

struts-default.xml文件位置 不用动 , 不需要 放在WEB-INF/class/中

 

 

你可能感兴趣的:(java,apache,Web,code,struts)