在myeclipse中已经导入了自带的struts框架,怎么把struts整合到spring中,也就是action交给spring管理
用spring IOC控制反转。配置下就行。
myEclipse整合SSH三大框架很方便的,它提供了右键菜单的,你选择项目然后右键就有添加SSH功能的选项了。
myeclipse 里面也有自带 spring 的
虽然没有struts但是用了spring mvc,可参考:http://git.oschina.net/wangkang/llsfw
可快速搭建开发环境,希望能够帮到你.
我的spring配置,你可以参考一下
application-action.xml
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="baseAction" class="cn.itcast.shop.action.BaseAction" scope="prototype">
<property name="accountService" ref="accountService" />
<property name="categoryService" ref="categoryService" />
<property name="goodsService" ref="goodsService" />
<property name="fileUploadUtil" ref="fileUploadUtil" />
<property name="sorderService" ref="sorderService" />
<property name="forderService" ref="forderService" />
<property name="usersService" ref="usersService" />
<property name="onlinePayService" ref="onlinePayService" />
<property name="shopEmaiUtill" ref="shopEmaiUtill" />
<property name="luceneServiceImpl" ref="luceneServiceImpl" />
<property name="roleService" ref="roleService" />
<property name="privilegeService" ref="privilegeService" />
</bean>
<bean id="forderAction" class="cn.itcast.shop.action.ForderAction" parent="baseAction" scope="prototype" />
<bean id="accountAction" class="cn.itcast.shop.action.AccountAction" parent="baseAction" scope="prototype" />
<bean id="categoryAction" class="cn.itcast.shop.action.CategoryAction" parent="baseAction" scope="prototype" />
<bean id="goodsAction" class="cn.itcast.shop.action.GoodsAction" parent="baseAction" scope="prototype" />
<bean id="sorderAction" class="cn.itcast.shop.action.SorderAction" parent="baseAction" scope="prototype" />
<bean id="usersAction" class="cn.itcast.shop.action.UsersAction" parent="baseAction" scope="prototype" />
<bean id="payAction" class="cn.itcast.shop.action.PayAction" parent="baseAction" scope="prototype" />
<bean id="roleAction" class="cn.itcast.shop.action.RoleAction" parent="baseAction" scope="prototype" />
application-bean.xml
<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!--
1: Spring来管理Hibernate配置文件,就是取代了HibernateSessionFactory
-->
<!-- 1: -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 加载hibernate的配置文件 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<!-- 2 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<!-- 需要sessionFactory -->
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="baseService" class="cn.itcast.shop.service.impl.BaseServiceImpl" lazy-init="true">
<property name="hibernateTemplate" ref="hibernateTemplate" />
</bean>
<!-- parent 在Spring配置文件中 找父类, 父类通过Spring的方式创建, 这样父类就可以实现依赖注入 -->
<bean id="logsService" class="cn.itcast.shop.service.impl.LogsServiceImpl" parent="baseService" />
<bean id="usersService" class="cn.itcast.shop.service.impl.UsersServiceImpl" parent="baseService" />
<bean id="forderService" class="cn.itcast.shop.service.impl.ForderServiceImpl" parent="baseService" />
<bean id="sorderService" class="cn.itcast.shop.service.impl.SorderServiceImpl" parent="baseService" />
<bean id="accountService" class="cn.itcast.shop.service.impl.AccountServiceImpl" parent="baseService" />
<bean id="categoryService" class="cn.itcast.shop.service.impl.CategoryServiceImpl" parent="baseService" />
<bean id="goodsService" class="cn.itcast.shop.service.impl.GoodsServiceImpl" parent="baseService" />
<bean id="roleService" class="cn.itcast.shop.service.impl.RoleServiceImpl" parent="baseService" />
<bean id="privilegeService" class="cn.itcast.shop.service.impl.PrivilegeServiceImpl" parent="baseService" />
<bean id="fileUploadUtil" class="cn.itcast.shop.util.FileUploadUtil">
<property name="filePath" value="D:\apache-tomcat-6.0.18\webapps\shop\image\" />
</bean>
<bean id="shopTimerTask" class="cn.itcast.shop.util.ShopTimerTask">
<property name="categoryService" ref="categoryService" />
<property name="goodsService" ref="goodsService" />
</bean>
<bean id="onlinePayService" class="cn.itcast.shop.service.impl.OnlinePayService" />
<bean id="shopEmaiUtill" class="cn.itcast.shop.util.ShopEmaiUtill" />
你只要将 struts-spring-xxx.jar 这个jar包加入项目就行了, 然后自动的你的action就是由spring去管理了
不信你打开这个jar包, 里面有一个 struts插件的xml文件 你看看这个文件里写的就知道了
还不信的话你就试试看你的Action类能不能自动注入一个配置在Spring管理下的bean就行了.