`
周禄康
  • 浏览: 158027 次
  • 性别: Icon_minigender_1
  • 来自: 石家庄
社区版块
存档分类
最新评论

Struts1.2+Spring2.5+Hibernate3.2框架搭建(十三)

    博客分类:
  • ssh
阅读更多

4.7. 修改Spring配制文件 applicationContext.xml

1)、定义工具类ZlkUtil节点

    <bean id="ZlkUtil" class="com.zlk.util.ZlkUtil"></bean>

2)、定义数据层UsersDaoImpl节点,注入HibernateSessionFactory对象sessionFactory(属性及对应setter方法通过继承HibernateDaoSupport而来)

    <bean id="UsersDaoImpl" class="com.zlk.dao.impl.UsersDaoImpl">

       <property name="sessionFactory" ref="sessionFactory"></property>

    </bean>

3)、定义业务层UsersBusinessImpl节点,注入IUsersDao的实现类对象UsersDaoImpl和工具类ZlkUtil对象ZlkUtil

    <bean id="UserBusinessImpl" class="com.zlk.business.impl.UsersBusinessImpl">

       <property name="usersDao" ref="UsersDaoImpl"></property>

       <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事务。

      修改<beans>标签的引用空间,增加对AOP事务的支持。

<beans xmlns="http://www.springframework.org/schema/beans" 

    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>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics