如何指定struts2配置文件的路径?
如何指定struts2配置文件的路径?
如题,我现在在用MyEclipse搭框架,想把所有的的配置文件都放在web-inf/cfg/目录下的,这样好统一管理.
看见书上写可以使用init param配个config参数的,然后指定配置文件的目录.但试了n久都没成功,老报空指针异常.....
把那个config参数去掉,再把struts.xml文件放到src目录就又好了......郁闷.
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>WEB-INF/cfg/struts.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</filter>
[解决办法]
在搭建的时候 会让你选择配置文件的目录啊 你选下就可以了!!
[解决办法]
在搭建的时候???你的意思是MyEclipse有 struts2 的插件了??
[解决办法]
URL没学好吧,
<param-value>WEB-INF/cfg/struts.xml</param-value>
WEB-INF前面要加/改成
<param-value>/WEB-INF/cfg/struts.xml</param-value>
[解决办法]
</filter-mapping>
<welcome-file-list>
<welcome-file>index.wml</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
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>
<!-- struts2 默认配置文件,必须加进来 有这里看出,当前文件的路径是跟路径下classes路径,所以其他的文件要从classes这个路径开始找 -->
<include file="struts-plugin.xml" />
<include file="struts-default.xml" />
<!-- 自己添加的配置文件 注意路径 -->
<include file="../struts2conf/mystruts.xml" />
<include file="../struts2conf/wml-struts.xml" />
</struts>
参考:http://cooler1217.iteye.com/blog/1222497
大部分人都是说这样解决的
但是我的问题没有解决。。。
[解决办法]
如果使用自定义的配置文件,还需要加入struts-default.xml,否则会报错:
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).