4.7. 修改Spring配製文件 applicationContext.xmljava
(1)、定義工具類ZlkUtil節點程序員
<bean id="ZlkUtil" class="com.zlk.util.ZlkUtil">bean>spring
(2)、定義數據層UsersDaoImpl節點,注入HibernateSessionFactory對象sessionFactory(屬性及對應setter方法經過繼承HibernateDaoSupport而來)express
<bean id="UsersDaoImpl" class="com.zlk.dao.impl.UsersDaoImpl">session
<property name="sessionFactory" ref="sessionFactory">property>架構
bean>app
(3)、定義業務層UsersBusinessImpl節點,注入IUsersDao的實現類對象UsersDaoImpl和工具類ZlkUtil對象ZlkUtil。工具
<bean id="UserBusinessImpl" class="com.zlk.business.impl.UsersBusinessImpl">網站
<property name="usersDao" ref="UsersDaoImpl">property>spa
<property name="zlkUtil" ref="ZlkUtil">property>
bean>
(4)、控制層」/login」節點,注入IUsersBusiness的實現類對象UsersBusinessImpl。
<bean name="/login" class="com.zlk.struts.action.LoginAction">
<property name="usersBusiness" ref="UserBusinessImpl">property>
bean>
(5)、增長AOP事務。
修改
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
">
增長事務。
< 指定事務管理器類,將sessionFactory注入,讓該事務管理器具備打開和關閉事務的能力 >
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
bean>
< 爲事務管理器類指定匹配器,經過用name指定的匹配字符串進行對對應的方法進行打開和關閉事務 >
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="deploy*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
tx:attributes>
tx:advice>
< 爲事務管理器類指定進行匹配的範圍,到指定的地方經過匹配器字符串進行篩選,對應上後爲該方法打開和關閉事務 >
<aop:config proxy-target-class="true">
<aop:pointcut id="managerOperation" expression="execution(* com.zlk.dao.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="managerOperation" />
aop:config>