先将所有的jar包build path一下,不然可能会有不知名错误
1 spring和struts整合是需要添加一个sturts2-spring-plugin-*.jar的jar包
2 如果将action也交给spring创建需要在action里面注入service &&【struts的scope应该为prototype】
applicationContext.xml:
<bean id="userAction" class="com.action.UserAction" scope="prototype">
<property name="userService" ref="userService"></property>
</bean>
3 修改struts.xml配置文件
4 在配置spring环境的时候在web.xml中如下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<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>