1.配置web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2加入spring包
spring.jar
struts2-spring-plugin-2.0.6.jar
3配置文件applicationContext.xml
<?xml version="1.0" encoding="GBK"?>
<!-- 指定Spring配置文件的Schema信息 -->
<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="myService" class="lee.MyServiceImpl"/>
<bean id="loginAction" class="lee.LoginAction" scope="prototype">
<property name="ms" ref="myService"/>
</bean>
</beans>
4引用
action中加入service属性
public class LoginAction implements Action
{
private MyService ms;
public void setMs(MyService ms)
{
this.ms = ms;
}
?只有setter。没有getter?
本文介绍了如何将Struts2与Spring框架进行集成,包括配置web.xml文件、引入必要的jar包、设置applicationContext.xml文件以及在Action类中注入Service等步骤。
549

被折叠的 条评论
为什么被折叠?



