java - datasource.xml配置文件求解
高洛峰
高洛峰 2017-04-18 09:21:29
0
1
466

配置文件如下:

<?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: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"
    default-autowire="byName">
    <bean id="dataSource" class="com.taobao.tddl.jdbc.group.TGroupDataSource" init-method="init">
        <property name="appName" value="IDCM_APP"/>
        <property name="dbGroupKey" value="IDCM_GROUP"/>
    </bean>
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
                <property name="mapperLocations" value="classpath*:com/**/dal/**/*Mapper*.xml" /> 
       <property name="dataSource" ref="dataSource" />
        <property name="typeAliasesPackage" value="com.alibaba.***.dal" />
    </bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="annotationClass" value="javax.annotation.Resource"></property>
        <property name="basePackage" value="com.alibaba.***.dal.***.mapper,com.alibaba.***.dal.***.***.mapper" />
    </bean>
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager" />
    <context:annotation-config />    
        <tx:advice id="defaultTxAdvice">
        <tx:attributes>
            <tx:method name="*" rollback-for="Exception" />
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut id="ao_bo"
            expression="(execution(* *..*BoImpl.*(..))) or ( execution(* *..*AoImpl.*(..)) and ( not execution(* *..*AoImpl.mtx_*(..)) ) )" />
        <aop:advisor pointcut-ref="ao_bo" advice-ref="defaultTxAdvice" />
    </aop:config>
    <context:component-scan base-package="com.alibaba.tboss.biz" />
</beans>

对上述配置文件的疑问点:

<bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    </bean>
    
    <tx:annotation-driven transaction-manager="transactionManager" />

    <context:annotation-config />    
        <tx:advice id="defaultTxAdvice">
        <tx:attributes>
            <tx:method name="*" rollback-for="Exception" />
        </tx:attributes>
    </tx:advice>

    <aop:config>
        <aop:pointcut id="ao_bo"
            expression="(execution(* *..*BoImpl.*(..))) or ( execution(* *..*AoImpl.*(..)) and ( not execution(* *..*AoImpl.mtx_*(..)) ) )" />
        <aop:advisor pointcut-ref="ao_bo" advice-ref="defaultTxAdvice" />
    </aop:config>

1.transactionManager这个配置了事务管理器,其中<aop:config> 这个标签中的配置,将boImpl.java中的每个方法封装成一个事务,如果有异常抛出,会执行事务的回滚,具体的关于这方面的知识,在哪儿可以找到?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

membalas semua(1)
洪涛

Jika anda boleh membaca bahasa Inggeris, sebaiknya pergi ke laman web rasmi
untuk mendapatkan maklumat secara langsung, yang tepat dan terperinci

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan