2010.04.08(4)———spring aop 事务控制
参考:http://pftx.spaces.live.com/blog/cns!A34683C50FDB4291!571.entry
http://www.blogjava.net/robbie/archive/2009/04/05/264003.html
http://blog.csdn.net/phoenixLotus/archive/2009/03/24/4020452.aspx
<?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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- 这是我们将要配置并使它具有事务性的Service对象 -->
<bean id="fooService" class="x.y.service.DefaultFooService"/>
//这个是事务语义
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true"/>
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!-- ensure that the above transactional advice runs for any execution
of an operation defined by the FooService interface -->
<aop:config>
<aop:pointcut id="fooServiceOperation" expression="execution(* x.y.service.FooService.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation"/>
</aop:config>
<!-- don't forget the DataSource -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@rj-t42:1521:elvis"/>
<property name="username" value="scott"/>
<property name="password" value="tiger"/>
</bean>
<!-- similarly, don't forget the (particular) PlatformTransactionManager -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
如果是spring+hibernate,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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- 这是我们将要配置并使它具有事务性的Service对象 -->
<bean id="fooService" class="x.y.service.DefaultFooService"/>
//这个是事务语义
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true"/>
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!-- ensure that the above transactional advice runs for any execution
of an operation defined by the FooService interface -->
<aop:config proxy-target-class="false">
<aop:advisor
pointcut="execution(* com.huitu.khms.dao.*.*(..))"
advice-ref="txAdvice" />
</aop:config>
</aop:config>
<!-- don't forget the DataSource -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@rj-t42:1521:elvis"/>
<property name="username" value="scott"/>
<property name="password" value="tiger"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</prop>
<prop key="show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
</props>
</property>
</bean>
<!-- similarly, don't forget the (particular) PlatformTransactionManager -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
分享到:
相关推荐
spring-aop-1.1.1.jar spring-aop-1.2.6.jar spring-aop-1.2.9.jar spring-aop-2.0.2.jar spring-aop-2.0.6.jar spring-aop-2.0.7.jar spring-aop-2.0.8.jar spring-aop-2.0.jar spring-aop-2.5.1.jar spring-aop-...
在Spring AOP的源码中,`org.springframework.aop.framework.ProxyFactoryBean`是创建代理的主要类,它会根据目标类是否有接口选择JDK动态代理或CGLIB。`org.aopalliance.intercept.MethodInterceptor`接口定义了...
开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE...
spring.jar spring-aop.jar spring-aop.jar spring-beans.jar spring-hibernate3.jar spring-jdbc.jar spring-struts.jar spring-web.jar
spring-aop-3.2.0.RELEASE.jar,一个Spring中AOP的jar包
spring-aop.jarspring-aop.jarspring-aop.jarspring-aop.jarspring-aop.jarspring-aop.jarspring-aop.jarspring-aop.jarspring-aop.jarspring-aop.jar
该jar文件包含了Spring AOP的核心类和接口,如`org.springframework.aop.*`包下的`AspectJExpressionPointcut`、`MethodBeforeAdvice`、`AfterReturningAdvice`等。 3. spring-aspects-4.1.6.RELEASE.jar:这个jar...
赠送jar包:spring-aop-5.2.0.RELEASE.jar; 赠送原API文档:spring-aop-5.2.0.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.2.0.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.2.0.RELEASE.pom;...
aopalliance-1.0.jar,org.springframework.aop-3.0.0.RELEASE.jar,org.springframework.jdbc-3.0.0.RELEASEorg.springframework.beans-3.0.0.RELEASE.jar等
spring-aop-5.0.0.RELEASE.jar;spring-aop-5.0.0.RELEASE.jar;spring-aop-5.0.0.RELEASE.jar
spring-aop-5.3.22.jar Spring AOP provides an Alliance-compliant aspect-oriented programming implementation allowing you to define method interceptors and pointcuts to cleanly decouple code that ...
Spring AOP(面向切面编程)是Spring框架的重要组成部分,它提供了一种强大的方式来实现横切关注点,如日志、事务管理、性能监控等,而无需侵入业务代码。下面将详细介绍Spring AOP的注解方式和XML配置方式。 ### ...
为了实现动态代理,Spring AOP通常会依赖于`spring-aop-xxx.jar`中的`org.springframework.aop.framework.ProxyFactoryBean`或者`org.springframework.aop.aspectj.autoproxy.AspectJAutoProxyCreator`类。...
spring-**core**-4.3.6.RELEASE.jar :包含spring框架基本的核心工具类,spring其他组件都要用到这个包里的类,其他组件的基本核心 spring-**beans**-4.3.6.RELEASE.jar:所有应用都要用到的jar包,它包含访问配置...
在 Spring AOP 中,`org.springframework.aop.framework.JdkDynamicAopProxy` 类实现了 `InvocationHandler` 接口,当代理对象的方法被调用时,实际会执行 `JdkDynamicAopProxy.invoke()` 方法。这个方法会检查并...
【标题】"org.apache.servicemix.bundles.spring-aspects-3.2.8.RELEASE_2.zip" 是一个基于Apache ServiceMix的Spring框架的特定模块——Spring Aspects的打包文件,版本为3.2.8.RELEASE。Spring Aspects是Spring...
spring-aop-5.2.0.RELEASE
这个库包含了一些核心的AOP接口,如`org.aopalliance.intercept.MethodInterceptor`和`org.aopalliance.aop.Advice`,这些接口定义了拦截器和通知(advice)的行为。在Spring AOP中,你可以使用这些接口来实现自定义...
【标题】"spring-aop.rar_java aop_spring aop" 涉及的主要知识点是Spring框架中的面向切面编程(AOP)以及Java基础知识。这个压缩包可能包含了一个简单的Spring AOP应用示例,同时也涵盖了Java的一些核心概念,如...