JavaEE开发框架-Spring-事务管理-学习日记

JavaEE开发框架-事务管理)

导包

配置文件

<?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:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.2.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">


    <!-- 数据源配置 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql://localhost:3306/spring3.2_10"></property>
        <property name="username" value="root"></property>
        <property name="password" value="root"></property>
        <!-- 初始化的连接数 -->
        <property name="initialSize" value="1"></property>
        <!-- 连接池的最大连接数-->
        <property name="maxActive" value="5"></property>
        <!-- 最大的空闲的连接数 -->
        <property name="maxIdle" value="2"></property>
        <!-- 最小的空闲连接数 -->
        <property name="minIdle" value="1"></property>
    </bean>

    <bean id="orderDao" class="com.daoimpl.OrderDaoImpl">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <bean id="detailDao" class="com.daoimpl.DetailDaoImpl">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <bean id="orderService" class="com.serviceimpl.OrderServiceImpl">
        <property name="orderDao" ref="orderDao"></property>
        <property name="detailDao" ref="detailDao"></property>
        <property name="detailService" ref="detailService"></property>
    </bean>

    <bean id="detailService" class="com.serviceimpl.DetailServiceImpl">
        <property name="detailDao" ref="detailDao"></property>
    </bean>


    <!-- 定义事务的管理器 -->
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!--
		通知配置
	 -->
    <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
            <!-- 具体的方法的配置 -->
            <tx:method name="save*" propagation="REQUIRED"/>
            <tx:method name="update*" propagation="REQUIRED"/>
            <tx:method name="query*" read-only="true"/>
        </tx:attributes>
    </tx:advice>

    <!--
        切面配置
     -->
    <aop:config>
        <!-- 切点配置:一般情况我们把切点配置在Service层 -->
        <aop:pointcut expression="execution(* com.serviceimpl..*.*(..))" id="mycut"/>
        <!--
            advice-ref:管理通知
            pointcut-ref:关联切点
         -->
        <aop:advisor advice-ref="txAdvice" pointcut-ref="mycut"/>
    </aop:config>
</beans>

``
``
发布了153 篇原创文章 · 获赞 93 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/JunSIrhl/article/details/104035337
今日推荐