- 在配置类(例:ApplicationConfig)上@Configuration,@EnableTransactionManagement
The @EnableTransactionManagement annotation provides equivalent support if you are using Java based configuration. Simply add the annotation to a@Configuration class. See the javadocs for full details.
- 尽量在具体实现类某个公开的方法(public)上加@Transactional
-
尽管官网说明可以把
@Transactional加在接口或接口方法上,但官方更推荐在具体实现类或公开方法上加事务
You can place the @Transactional annotation before an interface definition, a method on an interface, a class definition, or a public method on a class. However, the mere presence of the @Transactional annotation is not enough to activate the transactional behavior. The @Transactional annotation is simply metadata that can be consumed by some runtime infrastructure that is @Transactional-aware and that can use the metadata to configure the appropriate beans with transactional behavior. In the preceding example, the <tx:annotation-driven/> element switches on the transactional behavior.
|
Spring recommends that you only annotate concrete classes (and methods of concrete classes) with the |
2400

被折叠的 条评论
为什么被折叠?



