`
hunter090730
  • 浏览: 190953 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Spring2.5.6与struts2.3.1的整合

    博客分类:
  • SSH
 
阅读更多

环境:JDK1.6
IDE: MyEclipse6.1
jar:spring2.5.6,struts2-spring-plugin-2.2.1.jar等
步骤:
新建一个web project后,需作以下修改
1,修改web.xml ,添加listener后的如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>integration_web</display-name>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

</web-app>
2,修改applicationContext.xml
...
3,修改struts.xml
...
注意:如果将struts的Action交由spring来管理,则
struts action中的"class"应在spring中配置:
<action name="edit" class="editAction" method="input">
<result name="input">/edit.jsp</result>
</action>
如applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd">
           

<bean id="editService" class="org.apache.struts.edit.service.EditServiceInMemory" />
<!--Spring default the scope is "single",the struts2  action  is thread safty,so it's set  prototype here for struts2 action-->

<bean id="editAction" class="org.apache.struts.edit.action.EditAction" scope="prototype">

<property name="editService" ref="editService" />

</bean>

</beans>
即可;

但在这里,我遇到了一个额外的问题,

tomcat启动时出现的 严重: Error listenerStart

 

经过配置tomcat的log4j后,打印出来的错误才让知道原来是applicationContext.xml放错了位置。

applicationContext.xml需要放在跟web.xml同一级目录下。

在Tomcat中Log4j的配置如下:

 

以Tomcat5.5为例,tomcat5.5在默认情况下,并不会自动记录日志信息,需要人为配置。

1、在tomcat安装目录的common/classes中建立一个属性文件log4j.properties

2、在文件中写入日志的信息及日志记录的等级:

 

3、将log4j.jar和commons-logging.jar添加到tomcat目录下的common/lib目录中

4、完成

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics