struts2集成spring产生的问题

是了在用strut2集成spring,便是产生了一个问题,在网上找了一下也没找到解决方案,请大家看一下,帮忙解决一下:
struts2的版本是:2.1.6, 集成spring的时候用的是struts2-spring-plugin-2.1.6.jar
开发IDE是用的MyEclipse6.0.1, 服务器版本是Tomcat 6.0

然后集成之后,我是想用sping来对struts2的Action进行管理.

web.xml的内容如下:

<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/applicationContext.xml,classpath:applicationContext-*.xml
    </param-value>
</context-param>

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.FilterDispatcher
    </filter-class>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.jspa</url-pattern>
</filter-mapping>

<servlet>
    <servlet-name>velocity</servlet-name>
    <servlet-class>
        org.apache.velocity.tools.view.servlet.VelocityViewServlet
    </servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>velocity</servlet-name>
    <url-pattern>*.vm</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>dwr</servlet-name>
    <servlet-class>
        org.directwebremoting.servlet.DwrServlet
    </servlet-class>
    <init-param>
        <param-name>debug</param-name>
        <param-value>true</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>dwr</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

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">


<!-- 配置国际化信息 -->

<!-- 设置使用的解码集 -->

<package name="pages" namespace="/pages" extends="struts-default">
    <action name="display" class="DisplayAction">
        <result type="velocity">welcome.vm</result>
        <result name="showchart" type="velocity">sdv.vm</result>
        <result name="JSONTree" type="velocity">treedat.vm</result>
    </action>

    <action name="treedemo" class="TreedemoAction">
        <result type="velocity">treedemo.vm</result>
        <result name="treeJSON" type="velocity">treedat.vm</result>
    </action>

    <action name="inquire"  class="DWRInquireProcess">
        <result type="velocity">inquiredData.vm</result>
    </action>
</package>

struts.properties的内容如下:

struts.action.extension = jspa

struts.objectFactory = spring

struts.objectFactory.spring.autoWire = name

#for develop reason, we don't want the client browser cache the static content
struts.serve.static.browserCache = false

#we hope the server auto load the struts.xml file, when it is changed

struts.configuration.xml.reload = true

spring的配置文件applicationContext.xml的内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

class="com.intel.sdv2.action.DisplayPage">

<bean id="TreedemoAction" class="com.intel.sdv2.action.TreeDemo"></bean>

<bean id="DWRInquireProcess"
    class="com.intel.sdv2.action.DWRFormProcess">
</bean>

项目中用的jar包如下:

commons-logging-1.1.jar
freemarker-2.3.13.jar
ognl-2.6.11.jar
struts2-core-2.1.6.jar
xwork-2.1.2.jar
commons-digester-1.8.jar
commons-io-1.3.2.jar
commons-fileupload-1.2.1.jar
json-lib-2.1.jar
velocity-1.5.jar
velocity-tools-1.4.jar
commons-collections-3.2.jar
commons-lang-2.2.jar
dwr.jar

struts2-spring-plugin-2.1.6.jar

启动Tomcat时报的错如下:

2009-7-29 15:33:14 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: ... initialized Struts-Spring integration successfully
2009-7-29 15:33:14 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
java.lang.NullPointerException
at com.opensymphony.xwork2.util.FileManager$FileRevision.needsReloading(FileManager.java:209)
at com.opensymphony.xwork2.util.FileManager.fileNeedsReloading(FileManager.java:60)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.needsReload(XmlConfigurationProvider.java:325)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.needsReload(StrutsXmlConfigurationProvider.java:168)
at com.opensymphony.xwork2.config.ConfigurationManager.conditionalReload(ConfigurationManager.java:220)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:61)
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:774)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:191)
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:3696)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4343)
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)
2009-7-29 15:33:14 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2009-7-29 15:33:14 org.apache.catalina.core.StandardContext start
严重: Context [/SDVWeb2] startup failed due to previous errors
2009-7-29 15:33:14 org.apache.catalina.core.ApplicationContext log

信息: Closing Spring root WebApplicationContext

在没用集成Spring之间,一切运行都正常,当我把spring集成进去后,就报这样的错误了。弄不明白是什么原因?请大家看一下,有什么解决方法,谢谢!!!

3个回答

少2个包,一个spring.jar,还有个spring-core-2.5.jar,我昨天才解决的

根据 com.opensymphony.xwork2.util.FileManager$FileRevision.needsReloading(FileManager.java:209) 这个提示,debug吧
这样你可以学到更多的知识。

从你这里看是你的配置文件出现了错误,你的web.xml中struts2.0的那个filter路径是否对?查看你导入的jar包,还有你的spring的文件我怎么觉得缺少东西的呢,请帖出你spring的配置文件

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐