第一个:
事务的声明是在spring里面进行声明的.
org.springframework.jdbc.datasource.DataSourceTransactionManager
“>
需要引入tx命名空间
xmlns:tx=“http://www.springframework.org/schema/tx”
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
aop切面
在相应的service实现类上面添加:
@Transactional
第二个:springmvc的controller层上面添加
需要在controller类名现在加入注解!!!
将
添加在springmvc配置文件里面即可。
关键点:
spring和springmvc的配置文件加载时间不一样,所以在两个文件里面的注解自动扫描声明里面需要分开。
spring不扫描controller层代码,springmvc不扫描service层代码
例子:
2018.04.24
添加transactional这个注解的时候注意倒入spring的注解,
org.springframework.transaction.annotation.Transactional
单独使用@transactional不会起作用,有时候可能会是javax.transaction.transactional里面的!!!1