06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
这个配置文件很简单,唯一需要注意的是DispatcherServlet的配置。默认情况下Spring MVC根据Servlet的名字查找WEB-INF下的
将org.springframework.jdbc及org.springframework.transaction的日志级别设置为DEBUG,启 动项目,并访问http://localhost:8088/chapter10/logon.do userName=tom应 用,MixLayerUserService#logon方法将作出响应,查看后台输出日志,如下所示:
引用
Returning cached instance of singleton bean 'transactionManager'
Creating new transaction with name [com.baobaotao.mixlayer.MixLayerUserService.logon]:
PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
(DataSourceTransactionManager.java:204) - Acquired Connection [jdbc:mysql://localhost:3306/sampledb, UserName=root@localhost , MySQL-AB JDBC Driver] for JDBC transaction
(DataSourceTransactionManager.java:221) - Switching JDBC Connection [jdbc:mysql://localhost:3306/sampledb, UserName=root@localhost , MySQL-AB JDBC Driver] to manual commit
(JdbcTemplate.java:810) - Executing prepared SQL update
(JdbcTemplate.java:569) - Executing prepared SQL statement [UPDATE t_user u SET u.score = u.score + WHERE user_name = ]
(JdbcTemplate.java:819) - SQL update affected 0 rows
(AbstractPlatformTransactionManager.java:752) - Initiating transaction commit
(DataSourceTransactionManager.java:264) - Committing JDBC transaction on Connection [jdbc:mysql://localhost:3306/sampledb, UserName=root@localhost , MySQL-AB JDBC Driver]
日志中红色部分说明了MixLayerUserService#logon方法已经正确运行在事务上下文中。
Spring框架本身不应是代码复杂化的理由,使用Spring的开发者应该是无拘无束的:从实际应用出发,去除那些所谓原则性的接口,去掉强制分层的束缚,简单才是硬道理。