BeanNameAutoProxyCreator配置例子

 <?xml version="1.0" encoding="GBK"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

 <!-- 定义数据源Bean,使用C3P0数据源实现 -->
 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
  <!-- 指定连接数据库的驱动 -->
  <property name="driverClass" value="com.mysql.jdbc.Driver"/>
  <!-- 指定连接数据库的URL -->
  <property name="jdbcUrl" value="jdbc:mysql://localhost/j2ee"/>
  <!-- 指定连接数据库的用户名 -->
  <property name="user" value="root"/>
  <!-- 指定连接数据库的密码 -->
  <property name="password" value="32147"/>
  <!-- 指定连接数据库连接池的最大连接数 -->
  <property name="maxPoolSize" value="40"/>
  <!-- 指定连接数据库连接池的最小连接数 -->
  <property name="minPoolSize" value="1"/>
  <!-- 指定连接数据库连接池的初始化连接数 -->
  <property name="initialPoolSize" value="1"/>
  <!-- 指定连接数据库连接池的连接的最大空闲时间 -->
  <property name="maxIdleTime" value="20"/>
 </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

 <bean id="test1" class="lee.TransactionTestImpl">
  <property name="ds" ref="dataSource"/>
 </bean>

 <bean id="test2" class="lee.TestImpl">
  <property name="ds" ref="dataSource"/>
 </bean>

 <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
  <!-- 事务拦截器bean需要依赖注入一个事务管理器 -->
  <property name="transactionManager" ref="transactionManager"/>
  <property name="transactionAttributes">
   <!--  下面定义事务传播属性-->
   <props>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="*">PROPAGATION_REQUIRED</prop>
   </props>
  </property>
 </bean>

    <!-- 定义BeanNameAutoProxyCreator-->
    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
 <!-- 指定对满足哪些bean name的bean自动生成业务代理 -->
     <property name="beanNames">
            <!-- 下面是所有需要自动创建事务代理的bean-->
            <list>
                <value>test1</value>
                <value>test2</value>
            </list>
            <!-- 此处可增加其他需要自动创建事务代理的bean-->
     </property>
        <!--  下面定义BeanNameAutoProxyCreator所需的事务拦截器-->
        <property name="interceptorNames">
            <list>
                <value>transactionInterceptor</value>
                <!-- 此处可增加其他新的Interceptor -->
            </list>
        </property>
    </bean>

</beans>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值