您的位置:首页 > 编程语言 > Java开发

java-spring事务管理部分代码主要代码

2014-03-24 22:52 465 查看
此处以一个applicationContext.xml文件头部配置文件为例

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

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xmlns:context="http://www.springframework.org/schema/context"

       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-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/aop <!---------要添加的------------->

       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd<!---------要添加的------------->
       http://www.springframework.org/schema/tx <!---------要添加的------------->
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"><!---------要添加的------------->
//该处是配置事务管理的代码

<!--配置hibernate的事务管理器 -->

    <bean id="txManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">

        <propertyname="sessionFactory"ref="sessionFactory"/>

    </bean>

    <tx:adviceid="txadvice"transaction-manager="txManager">

    <tx:attributes>

        <tx:methodname="save*"propagation="REQUIRED"isolation="DEFAULT"/>

        <tx:methodname="delete*"propagation="REQUIRED"isolation="DEFAULT"/>

        <tx:methodname="find*"read-only="false"/>

        <tx:methodname="get*"read-only="false"/>

    </tx:attributes>

    </tx:advice> 

<!--配置切面 -->

    <aop:config>

        <aop:pointcutid="commonPointcut"expression="execution(*
*..service..*.*(..))"/>

        <aop:advisoradvice-ref="txadvice"pointcut-ref="commonPointcut"/>

    </aop:config>

    <beanid="hibernateTemplate"class="org.springframework.orm.hibernate3.HibernateTemplate">

        <propertyname="sessionFactory"ref="sessionFactory"/>

    </bean>

    <beanid="baseDao"class="com.util.dao.imp.BaseDao">

      <propertyname="hibernateTemplate"><refbean="hibernateTemplate"/></property>

    </bean>

    <beanid="baseService"class="com.util.service.imp.BaseService"abstract="true"/>

   

</beans>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: