`
isiqi
  • 浏览: 16706342 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

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>

分享到:
评论

相关推荐

    AOP usage -- BeanNameAutoProxyCreator usage

    **一、配置BeanNameAutoProxyCreator** 在Spring配置文件中,我们需要声明一个`BeanNameAutoProxyCreator` bean,并设置其属性。主要的属性有: 1. `proxyTargetClass`: 是否使用CGLIB代理,默认为false,如果设为...

    Spring + Hibernate + Struts 事务配置小例子(带提示框等小技巧)

    前几天搞 Spring + Hibernate + Struts 事务配置 ,网上找了好多资料,不过好无语,大多都是 Ctrl + V,浪费俺的宝贵时间 现在我总结配出一套,给大家参考参考,可能有不足,请大家多多交流。 附:内有弹出...

    spring 事务代理配置

    3. **使用DefaultAdvisorAutoProxyCreator**:与`BeanNameAutoProxyCreator`类似,但其配置的可读性可能稍逊一筹。 #### 总结 在Spring框架中,声明式事务管理是一种强大而灵活的事务处理方式,尤其是通过`...

    Spring实现自动代理Demo

    在`springtest`项目中,你可以找到一个简单的例子来演示`BeanNameAutoProxyCreator`的使用。项目中可能包括以下组件: - 一个或多个需要被代理的bean,如`UserService`。 - 定义拦截器的类,如`LoggingAspect`,...

    spring拦截器的简单例子.docx

    在这个简单的例子中,我们将深入理解如何配置和使用 Spring 的拦截器来实现特定的功能。 首先,我们有一个接口 `Purview`,其中包含一个方法 `logincheck()`。这个接口定义了需要被拦截的方法。接口的作用是提供一...

    Spring.3.x企业应用开发实战(完整版).part2

    6.5.2 BeanNameAutoProxyCreator 6.5.3 DefaultAdvisorAutoProxyCreator 6.6 小结 第7章 基于@AspectJ和Schema的AOP 7.1 Spring对AOP的支持 7.2 JDK 5.0注解知识快速进阶 7.2.1 了解注解 7.2.2 一个简单的注解类 ...

    Java实训教程 Java软件开发实战 Java开发框架 log4jdbc 共5页.pptx

    以下是如何在Spring XML配置文件中进行设置的例子: ```xml &lt;bean id="dataSourceLog4jdbcAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"&gt; &lt;value&gt;log4...

    Spring3.x企业应用开发实战(完整版) part1

    6.5.2 BeanNameAutoProxyCreator 6.5.3 DefaultAdvisorAutoProxyCreator 6.6 小结 第7章 基于@AspectJ和Schema的AOP 7.1 Spring对AOP的支持 7.2 JDK 5.0注解知识快速进阶 7.2.1 了解注解 7.2.2 一个简单的注解类 ...

    Spring+Ibatis 访问多个数据源

    为了实现事务管理,我们可以使用Spring的`DataSourceTransactionManager`,为每个数据源配置一个事务管理器,并通过AOP代理(例如`BeanNameAutoProxyCreator`)指定事务拦截器: ```xml ...

    Spring-Reference_zh_CN(Spring中文参考手册)

    BeanNameAutoProxyCreator 7.9.1.2. DefaultAdvisorAutoProxyCreator 7.9.1.3. AbstractAdvisorAutoProxyCreator 7.9.2. 使用元数据驱动的自动代理 7.10. 使用TargetSources 7.10.1. 热交换目标源 7.10.2. 池化目标...

Global site tag (gtag.js) - Google Analytics