spring在xml中事务声明配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">
    
    <!-- database 连接配置 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

    <context:property-placeholder  location="conf/jdbc/jdbc.properties" />
    
    <!-- 配置Hibernate 因用的spring4.1.6版本所以 这里需hibernate4版本 -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!-- 在spring中加载hibernate.cfg.xml配置 -->
        <property name="configLocation" value="classpath:conf/hibernate/hibernate.cfg.xml" />
        <!-- <property name="mappingResources"> <value>conf/model/student.hbm.xml</value>
            </property> 这里是spring中加载hibernate实体配置文件,因考虑项目分工,个人建议还是将实体映射交给hibernate处理-->
    </bean>
     <!-- AOP切面进去,告诉方法用transation -->
    <aop:config>
        <aop:pointcut expression="execution(* org.ssh.service.*.*(..))"  id="servicePointcut"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointcut"/>
    </aop:config>
    
    <!-- spring事务管理 -->
 <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
</bean>
    <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
            <!-- 一下内容为凡是方法名以get、query、find开头的都是readonly,其他军事默认是REQUIRED -->
            <tx:method name="get*" read-only="true" />
            <tx:method name="query*" read-only="true" />
            <tx:method name="find*" read-only="true"  />
            <tx:method name="add*" propagation="REQUIRED"/>
            <!-- 在spring中默认就是required -->
        </tx:attributes>
    </tx:advice>
        

    <import resource="student_spring.xml" />
</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值