有两种方式,一种是spring作为struts的插件,就在struts的plugin配置。
还有一种,就是spring不与struts集成。先说第一种:
struts-config.xml:
<action path="/FileBoxUpdate" 
name="fileBaseInfoForm"
type="org.springframework.web.struts.DelegatingActionProxy" 
parameter="method" scope="request" validate="false">
</action>
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/spring-context/applicationContext.xml"/>
</plug-in>applicationContext.xml:
<beans>
<!-- dataSource config -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/wehaveoa</value>
</property>
</bean>
<!-- 配置sessionFactory, 注意这里引入的包的不同  -->
<bean id="SessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="configLocation">
<value>classpath:com\wehave\bean\hibernate\hibernate.cfg.xml</value>
</property>
</bean>

<!-- 配置transactionManager, 注意这里引入的包的不同  -->
<bean id="TransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="SessionFactory"/>
</property>
</bean><!-- MachineFileBaseInfoDAO -->
<bean id="MachineFileBaseInfoDAO" class="com.wehave.oa.machinefile.dao.hibernate.MachineFileBaseInfoDAOImp">
<property name="sessionFactory">
<ref bean="SessionFactory"/>
</property>
</bean>

<!-- MachineFileBaseInfoService -->
<bean id="MachineFileBaseInfoService" class="com.wehave.oa.machinefile.service.MachineFileBaseInfoService">
<property name="machineFileBaseInfoDAO">
<ref bean="MachineFileBaseInfoDAO"/>
</property>
</bean><bean name="/machinefile/FileBoxUpdate" class="com.wehave.oa.machinefile.web.action.FileBaseInfoAction" singleton="false">
<property name="machineFileBaseInfoService">
<ref bean="MachineFileBaseInfoService"/>
</property>
</bean>
</beans>