2009年10月15日 星期四 09:39 A.M.
转:http://blog.163.com/whyy0/blog/static/7407007200942333359429/ 由struts2-showcase 的 NullPointerException 解决方法
想运行struts2.1.6自带的例子showcase,把war包拷贝到tomcat6.0的webapp下,
输入"http://localhost:8080/struts2-showcase-2.1.6",结果报错
java.lang.NullPointerException
com.opensymphony.xwork2.util.FileManager$FileRevision.needsReloading(FileManager.java:209) com.opensymphony.xwork2.util.FileManager.fileNeedsReloading(FileManager.java:60) com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.needsReload(XmlConfigurationProvider.java:325) org.apache.struts2.config.StrutsXmlConfigurationProvider.needsReload(StrutsXmlConfigurationProvider.java:168) com.opensymphony.xwork2.config.ConfigurationManager.conditionalReload(ConfigurationManager.java:220) com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:61) org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:774) org.apache.struts2.dispatcher.ng.PrepareOperations.createActionContext(PrepareOperations.java:74) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter.doFilter(StrutsPrepareFilter.java:59) 随即百度了一下,在class下的struts.xml文件中, 有个devMode的设定为true,将其设置为false,或者注释掉就可以了。
<constant name="struts.devMode" value="true"></constant>
constant 是常量的设置,可以在多个文件中声明,默认的,Struts2框架按照以下的顺序搜索常量,越靠后的优先级越高。
①struts-default.xml
②struts-plugin.xml ③struts.xml ④struts.properties ⑤web.xml stutus.xml的配置方法
<constant name="struts.devMode" value="true"></constant>
struts.propertis的配置方法
struts.devMode=true
web.xml的配置方法
<init-param>
<param-name>struts.devMode</param-name> <param-valus>true</param-value> </init-param> 补充一下 这个问题是struts的bug,把lib里的xwork的jar文件换成最新版的2.1.4,可以从根本上解决这个问题。但是xwork 2.1.4里竟然没有com/opensymphony/xwork2/util/TextUtils,不理解xwork为什么要做的向下不兼容,还只是翻个小版本,没有办法我把2.1.2的jar也考到lib里,2.1.4优先一下,暂时是没有问题了,只能等待struts2.1.7的发布了 |