applicationContext,xml!-- 导入资源文件 -- context:property-placeholder locationclasspath:db.properties/ !-- 配置 C3P0 数据源 -- bean iddataSource classcom.mchange.v2.c3p0.ComboPooledDataSource property nameuser value${jdbc.user}/property property namepassword value${jdbc.password}/property property namejdbcUrl value${jdbc.jdbcUrl}/property property namedriverClass value${jdbc.driverClass}/property property nameinitialPoolSize value${jdbc.initPoolSize}/property property namemaxPoolSize value${jdbc.maxPoolSize}/property /bean !-- 1. 配置事务管理器 -- bean idtransactionManager classorg.springframework.jdbc.datasource.DataSourceTransactionManager property namedataSource refdataSource/property /bean !-- 2. 配置事务属性 -- tx:advice idtxAdvice transaction-managertransactionManager tx:attributes !--使用 propagation 指定事务的传播行为当前事务方法被另一个事务方法调用时如何使用事务默认值 REQUIRED使用调用方法的事务 REQUIRES_NEW事务自己的事务调用的事务方法的事务挂起-- tx:method namepurchase propagationREQUIRES_NEW/tx:method !-- 方法名 getfind 开始的方法 -- tx:method nameget* read-onlytrue/tx:method tx:method namefind* read-onlytrue/tx:method tx:method name*/ /tx:attributes /tx:advice !-- 3. 配置切入点以及把事务切入点和事务属性关联起来 -- aop:config aop:pointcut idtxPointCut expressionexecution(* demo.tx.BookShopService.*(..))/aop:pointcut aop:advisor advice-reftxAdvice pointcut-reftxPointCut/aop:advisor /aop:config
Spring 配置事务管理器-xml的方式
发布时间:2026/7/16 18:05:38
applicationContext,xml!-- 导入资源文件 -- context:property-placeholder locationclasspath:db.properties/ !-- 配置 C3P0 数据源 -- bean iddataSource classcom.mchange.v2.c3p0.ComboPooledDataSource property nameuser value${jdbc.user}/property property namepassword value${jdbc.password}/property property namejdbcUrl value${jdbc.jdbcUrl}/property property namedriverClass value${jdbc.driverClass}/property property nameinitialPoolSize value${jdbc.initPoolSize}/property property namemaxPoolSize value${jdbc.maxPoolSize}/property /bean !-- 1. 配置事务管理器 -- bean idtransactionManager classorg.springframework.jdbc.datasource.DataSourceTransactionManager property namedataSource refdataSource/property /bean !-- 2. 配置事务属性 -- tx:advice idtxAdvice transaction-managertransactionManager tx:attributes !--使用 propagation 指定事务的传播行为当前事务方法被另一个事务方法调用时如何使用事务默认值 REQUIRED使用调用方法的事务 REQUIRES_NEW事务自己的事务调用的事务方法的事务挂起-- tx:method namepurchase propagationREQUIRES_NEW/tx:method !-- 方法名 getfind 开始的方法 -- tx:method nameget* read-onlytrue/tx:method tx:method namefind* read-onlytrue/tx:method tx:method name*/ /tx:attributes /tx:advice !-- 3. 配置切入点以及把事务切入点和事务属性关联起来 -- aop:config aop:pointcut idtxPointCut expressionexecution(* demo.tx.BookShopService.*(..))/aop:pointcut aop:advisor advice-reftxAdvice pointcut-reftxPointCut/aop:advisor /aop:config