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>