项目中spring事务管理配置分析与修改方案

概要:

  • 现有spring事务管理配置存在问题:
    对数据库无关的service层方法,也会进行事务管理(创建数据库链接、提交(回滚)事务、释放连接等),消耗资源。

  • 修改方案:
    只对执行数据库写操作的service层方法进行事务管理,其它方法均不做配置。

  • 需要做的工作:
    统计现有service层方法命名;修改事务管理配置文件;规范后续开发时的service层方法命名。

  • 后续工作
    1、确定事务管理机制
    2、清理现有service层方法命名及功能
    3、按确定的事务管理机制修改事务管理配置
    4、规范以后的方法命名。

现有配置

配置如下:

<tx:method name="get*" read-only="true" />

<tx:method name="query*" read-only="true" />

<tx:method name="*" propagation="REQUIRED" />

日志输出:

  1. com.sinosig.carpremium.services.impl.TokenServiceImpl.countToken

创建事务
2012-01-17 11:46:39,656 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction:371] - Creating new transaction with name [com.sinosig.carpremium.services.impl.TokenServiceImpl.countToken]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
建立链接
2012-01-17 11:46:58,375 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin:202] - Acquired Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver] for JDBC transaction
2012-01-17 11:46:58,468 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin:219] - Switching JDBC Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver] to manual commit
执行处理逻辑
2012-01-17 11:46:58,468 INFO [com.sinosig.carpremium.services.impl.TokenServiceImpl.countToken:44] - 令牌基数是:100000,当前令牌值是:1
commit预处理
2012-01-17 11:46:58,468 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit:903] - Triggering beforeCommit synchronization
2012-01-17 11:46:58,468 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCompletion:916] - Triggering beforeCompletion synchronization
2012-01-17 11:46:58,468 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit:730] - Initiating transaction commit
提交事务
2012-01-17 11:46:58,484 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit:259] - Committing JDBC transaction on Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver]
Commit后处理
2012-01-17 11:46:58,484 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCommit:929] - Triggering afterCommit synchronization
2012-01-17 11:46:58,484 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion:945] - Triggering afterCompletion synchronization
释放数据库链接
2012-01-17 11:46:58,484 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doCleanupAfterCompletion:314] - Releasing JDBC Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver] after transaction

  1. com.sinosig.carpremium.services.impl.AutocompleteServiceImpl.getTravelHotCityList

创建事务
2012-01-17 11:47:05,687 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction:371] - Creating new transaction with name [com.sinosig.carpremium.services.impl.AutocompleteServiceImpl.getTravelHotCityList]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
创建数据库链接
012-01-17 11:47:05,687 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin:202] - Acquired Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver] for JDBC transaction
2012-01-17 11:47:05,687 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin:219] - Switching JDBC Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver] to manual commit
执行逻辑
2012-01-17 11:47:05,765 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Connection
2012-01-17 11:47:05,781 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Preparing Statement:    Select p.City city, p.Spelling spelling, p.Org_Id   orgId,p.spelling_acronym spellingAcronym,p.city_plate cityPlate   ,a.PRO_PLATE provincePlate   From t_Se_City p left join t_se_netCityControl a      on p.org_id = a.org_id    Where p.hot_sign=? and a.isnew = '1' Order By p.city_id   Asc  
2012-01-17 11:47:05,953 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Executing Statement:    Select p.City city, p.Spelling spelling, p.Org_Id   orgId,p.spelling_acronym spellingAcronym,p.city_plate cityPlate   ,a.PRO_PLATE provincePlate   From t_Se_City p left join t_se_netCityControl a      on p.org_id = a.org_id    Where p.hot_sign=? and a.isnew = '1' Order By p.city_id   Asc  
2012-01-17 11:47:05,953 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Parameters: [1]
2012-01-17 11:47:05,968 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Types: [java.lang.String]
2012-01-17 11:47:06,015 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  ResultSet
2012-01-17 11:47:06,031 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Header: [CITY, SPELLING, ORGID, SPELLINGACRONYM, CITYPLATE, PROVINCEPLATE]
2012-01-17 11:47:06,031 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [北京市, BeiJingShi, 01682900, bjs, 京, 京]
2012-01-17 11:47:06,031 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [济南市, JiNanShi, 02129700, jns, 鲁A, 鲁A]
2012-01-17 11:47:06,046 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [南京市, NanJingShi, 03515500, njs, 苏A, 苏]
2012-01-17 11:47:06,046 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [重庆市, ChongQingShi, 05141600, cqs, 渝, 渝]
2012-01-17 11:47:06,046 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [郑州市, ZhengZhouShi, 06511000, zzs, 豫A, 豫]
2012-01-17 11:47:06,046 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [上海市, ShangHaiShi, 07518800, shs, 沪, 沪]
2012-01-17 11:47:06,046 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [广州市, GuangZhouShi, 08512200, gzs, 粤A, 粤]
2012-01-17 11:47:06,046 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [深圳市, ShenZhenShi, 09101800, szs, 粤B, 粤B]
2012-01-17 11:47:06,046 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [青岛市, QingDaoShi, 11402000, qds, 鲁B, 鲁B]
2012-01-17 11:47:06,062 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [石家庄市, ShiJiaZhuangShi, 15503200, sjzs, 冀A, 冀]
2012-01-17 11:47:06,062 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [杭州市, HangZhouShi, 19503500, hzs, 浙A, 浙]
2012-01-17 11:47:06,062 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [成都市, ChengDuShi, 21114000, cds, 川A, 川]
提交预操作
2012-01-17 11:47:06,062 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit:903] - Triggering beforeCommit synchronization
2012-01-17 11:47:06,078 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCompletion:916] - Triggering beforeCompletion synchronization
2012-01-17 11:47:06,078 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit:730] - Initiating transaction commit
提交事务
2012-01-17 11:47:06,078 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit:259] - Committing JDBC transaction on Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver]
提交后操作
2012-01-17 11:47:06,093 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCommit:929] - Triggering afterCommit synchronization
2012-01-17 11:47:06,093 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion:945] - Triggering afterCompletion synchronization
2012-01-17 11:47:06,093 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doCleanupAfterCompletion:314] - Releasing JDBC Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver] after transaction

问题:

与数据库无关的service层操作也被纳入了事务管理的范围里。事务管理和数据库操作都会占用系统资源。

方案

方案一:对数据库增/删/改操作的操作进行事务管理,其余均不做配置。

配置如下。

<tx:method name="add*" propagation="REQUIRED" />

<tx:method name="save*" propagation="REQUIRED" />

<tx:method name="update*" propagation="REQUIRED" />

<tx:method name="edit*" propagation="REQUIRED" />

<tx:method name="remove*" propagation="REQUIRED" />

<tx:method name="delete*" propagation="REQUIRED" />

日志记录

  1. com.sinosig.carpremium.services.impl.TokenServiceImpl.countToken

2012-01-17 12:11:29,578 INFO [com.sinosig.carpremium.services.impl.TokenServiceImpl.countToken:44] - 令牌基数是:100000,当前令牌值是:1

  1. com.sinosig.carpremium.services.impl.AutocompleteServiceImpl.getTravelHotCityList

2012-01-17 12:11:35,312 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Connection
2012-01-17 12:11:53,765 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Preparing Statement:    Select p.City city, p.Spelling spelling, p.Org_Id   orgId,p.spelling_acronym spellingAcronym,p.city_plate cityPlate   ,a.PRO_PLATE provincePlate   From t_Se_City p left join t_se_netCityControl a      on p.org_id = a.org_id    Where p.hot_sign=? and a.isnew = '1' Order By p.city_id   Asc  
2012-01-17 12:11:53,953 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Executing Statement:    Select p.City city, p.Spelling spelling, p.Org_Id   orgId,p.spelling_acronym spellingAcronym,p.city_plate cityPlate   ,a.PRO_PLATE provincePlate   From t_Se_City p left join t_se_netCityControl a      on p.org_id = a.org_id    Where p.hot_sign=? and a.isnew = '1' Order By p.city_id   Asc  
2012-01-17 12:11:53,953 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Parameters: [1]
2012-01-17 12:11:53,953 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Types: [java.lang.String]
2012-01-17 12:11:54,000 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  ResultSet
2012-01-17 12:11:54,015 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Header: [CITY, SPELLING, ORGID, SPELLINGACRONYM, CITYPLATE, PROVINCEPLATE]
2012-01-17 12:11:54,015 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [北京市, BeiJingShi, 01682900, bjs, 京, 京]
2012-01-17 12:11:54,015 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [济南市, JiNanShi, 02129700, jns, 鲁A, 鲁A]
2012-01-17 12:11:54,046 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [南京市, NanJingShi, 03515500, njs, 苏A, 苏]
2012-01-17 12:11:54,046 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [重庆市, ChongQingShi, 05141600, cqs, 渝, 渝]
2012-01-17 12:11:54,046 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [郑州市, ZhengZhouShi, 06511000, zzs, 豫A, 豫]
2012-01-17 12:11:54,046 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [上海市, ShangHaiShi, 07518800, shs, 沪, 沪]
2012-01-17 12:11:54,062 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [广州市, GuangZhouShi, 08512200, gzs, 粤A, 粤]
2012-01-17 12:11:54,062 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [深圳市, ShenZhenShi, 09101800, szs, 粤B, 粤B]
2012-01-17 12:11:54,062 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [青岛市, QingDaoShi, 11402000, qds, 鲁B, 鲁B]
2012-01-17 12:11:54,062 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [石家庄市, ShiJiaZhuangShi, 15503200, sjzs, 冀A, 冀]
2012-01-17 12:11:54,062 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [杭州市, HangZhouShi, 19503500, hzs, 浙A, 浙]
2012-01-17 12:11:54,062 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [成都市, ChengDuShi, 21114000, cds, 川A, 川]

  1. com.sinosig.carchannel.services.impl.NetInfoServcieImpl.saveNetInfo

2012-01-17 12:17:58,437 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction:371] - Creating new transaction with name [com.sinosig.carchannel.services.impl.NetInfoServcieImpl.saveNetInfo]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2012-01-17 12:17:58,437 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin:202] - Acquired Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver] for JDBC transaction
2012-01-17 12:17:58,515 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin:219] - Switching JDBC Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver] to manual commit
2012-01-17 12:17:58,546 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Connection
2012-01-17 12:17:58,546 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Preparing Statement:     select SEQ_INSUINFO.nextval from dual   
2012-01-17 12:17:58,546 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Executing Statement:     select SEQ_INSUINFO.nextval from dual   
2012-01-17 12:17:58,546 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Parameters: []
2012-01-17 12:17:58,546 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Types: []
2012-01-17 12:17:58,562 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  ResultSet
2012-01-17 12:17:58,562 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Header: [NEXTVAL]
2012-01-17 12:17:58,562 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [15081689]
2012-01-17 12:17:58,562 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Preparing Statement:       insert into   T_SE_INSURANCE_INFO(PK_T_INS_ID,CONT_TEL,PROV_CITY,USEYEAR,   NUM_PLATE,PURCHASE_DATE,PRICE,IS_NEW,INSU_APP_DATE,CONT_NAME,   PUSHED_FLAG,PURGECODE,AREACODE,EMAIL,SPSOURCE,HASDRI,INSU_APP_DATE_TRA)   values(?,?,?,?,   ?,?,?,?,to_date(?,'yyyy-MM-dd'),?,   '9',?,?,?,?,'0',?)  
2012-01-17 12:17:58,562 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Executing Statement:       insert into   T_SE_INSURANCE_INFO(PK_T_INS_ID,CONT_TEL,PROV_CITY,USEYEAR,   NUM_PLATE,PURCHASE_DATE,PRICE,IS_NEW,INSU_APP_DATE,CONT_NAME,   PUSHED_FLAG,PURGECODE,AREACODE,EMAIL,SPSOURCE,HASDRI,INSU_APP_DATE_TRA)   values(?,?,?,?,   ?,?,?,?,to_date(?,'yyyy-MM-dd'),?,   '9',?,?,?,?,'0',?)  
2012-01-17 12:17:58,562 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Parameters: [15081689, 13800138000, 02129700, 5, 鲁A423423, 2007-01-17, , 0, 2012-01-18,  , WB-OB-NR-FQ, W00000002, , NET, 2012-01-18]
2012-01-17 12:17:58,562 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Types: [java.lang.Long, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String]
2012-01-17 12:17:58,578 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit:903] - Triggering beforeCommit synchronization
2012-01-17 12:17:58,578 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCompletion:916] - Triggering beforeCompletion synchronization
2012-01-17 12:17:58,578 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit:730] - Initiating transaction commit
2012-01-17 12:17:58,578 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit:259] - Committing JDBC transaction on Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver]
2012-01-17 12:17:58,578 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCommit:929] - Triggering afterCommit synchronization
2012-01-17 12:17:58,578 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion:945] - Triggering afterCompletion synchronization
2012-01-17 12:17:58,593 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doCleanupAfterCompletion:314] - Releasing JDBC Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver] after transaction

  1. com.sinosig.carchannel.services.impl.NetRuleServiceImpl.saveRuleInfo

2012-01-17 12:17:58,593 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction:371] - Creating new transaction with name [com.sinosig.carchannel.services.impl.NetRuleServiceImpl.saveRuleInfo]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2012-01-17 12:17:58,593 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin:202] - Acquired Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver] for JDBC transaction
2012-01-17 12:17:58,593 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin:219] - Switching JDBC Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver] to manual commit
2012-01-17 12:17:58,593 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Connection
2012-01-17 12:17:58,593 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Preparing Statement:     select SEQ_RULE.nextval from dual   
2012-01-17 12:17:58,593 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Executing Statement:     select SEQ_RULE.nextval from dual   
2012-01-17 12:17:58,593 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Parameters: []
2012-01-17 12:17:58,593 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Types: []
2012-01-17 12:17:58,609 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  ResultSet
2012-01-17 12:17:58,609 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Header: [NEXTVAL]
2012-01-17 12:17:58,609 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Result: [60910]
2012-01-17 12:17:58,609 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Preparing Statement:       insert into T_SE_RULE(ID,PK_T_INS_ID,MULTIRISKTYPE,   CUSTOMERLOYALTY,DAMAGEDFACTORGRADE,RUNAREACODE,RUNMILES,ADDONCOUNT,ParticularModel,DISCOUNT)   values(?,?,?,   ?,?,?,?,?,?,'1.0')  
2012-01-17 12:17:58,609 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Executing Statement:       insert into T_SE_RULE(ID,PK_T_INS_ID,MULTIRISKTYPE,   CUSTOMERLOYALTY,DAMAGEDFACTORGRADE,RUNAREACODE,RUNMILES,ADDONCOUNT,ParticularModel,DISCOUNT)   values(?,?,?,   ?,?,?,?,?,?,'1.0')  
2012-01-17 12:17:58,609 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Parameters: [60910, 15081689, 1, 1, 1, 1, 1, 1, 0]
2012-01-17 12:17:58,609 DEBUG [com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl.debug:27] -  Types: [java.lang.Long, java.lang.Long, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String]
2012-01-17 12:17:58,609 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit:903] - Triggering beforeCommit synchronization
2012-01-17 12:17:58,609 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCompletion:916] - Triggering beforeCompletion synchronization
2012-01-17 12:17:58,625 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit:730] - Initiating transaction commit
2012-01-17 12:17:58,625 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit:259] - Committing JDBC transaction on Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver]
2012-01-17 12:17:58,625 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCommit:929] - Triggering afterCommit synchronization
2012-01-17 12:17:58,625 DEBUG [org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion:945] - Triggering afterCompletion synchronization
2012-01-17 12:17:58,625 DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager.doCleanupAfterCompletion:314] - Releasing JDBC Connection [jdbc:oracle:thin:@10.10.114.161:1521:ifpdb, UserName=AUTOCREAT, Oracle JDBC driver] after transaction

结果

从上述日志可见:

  • 对数据库无关的操作(如countToken)不再进行事务管理;
  • 对读取数据库的操作(如查找热门城市)也不再进行事务管理;
  • 对写数据库的操作(如saveNetInfo、saveRuleInfo)仍进行可回滚的事务管理。

后续工作

  1. 整理现有的service层操作方法名
  2. 后续开发中规范service层操作方法命名。