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

来源:互联网 发布:淘宝一手货源一件代发 编辑:程序博客网 时间:2024/06/11 08:29

此处以一个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>





0 0
原创粉丝点击