struts2配置文件路径

请求时报以下异常:

com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=com.opensymphony.xwork2.ObjectFactory, name='default'] in public void com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.setObjectFactory(com.opensymphony.xwork2.ObjectFactory). - Class: com.opensymphony.xwork2.inject.ContainerImpl File: ContainerImpl.java

 

原因是自定义了struts的配置文件路径,但是路径指向不正确。默认情况下struts2会在classpath下加载默认配置文件struts.xml和struts-default.xml(在struts2-core.jar下)和struts-plugin.xml(在相关struts2插件jar包中)【可选】。

 

如果通过config参数指定配置文件路径,那么这几个默认配置文件路径都要显式指定一下:

 

<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-default.xml,struts-plugin.xml,struts/struts.xml</param-value>
		</init-param>
	</filter>

 注意前面不需要"/"。

 

另外一个需要注意的地方就是,使用include指令包含文件时:

struts.xml的配置:

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

	<constant name="struts.devMode" value="true" />
	<constant name="struts.action.extension" value="action" />
	<constant name="struts.objectFactory" value="spring" />

	<include file="struts/struts-config.xml" />

</struts>

 是相对于classpath根目录的路径,而不是相对于文件的路径。比如说上面的配置,struts.xml在classpath的struts目录下,struts-config.xml也在同一目录下,但是include中file的路径要写成struts/struts-config.xml,而不是struts-config.xml。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值