简体   繁体   English

如何在JdbcTemplate中忽略@Transactional

[英]How to ignore @Transactional in JdbcTemplate

I'd like to create a library (jar) and use JdbcTemplate in it to simplify working with Database. 我想创建一个库(jar)并在其中使用JdbcTemplate来简化数据库的使用。 But that library will be used in other Spring applications. 但是该库将在其他Spring应用程序中使用。 And by default @Transactional annonations in application will affect the methods in library (JdbcTemplate in library will be aware of that outer Transaction). 默认情况下,应用程序中的@Transactional注释会影响库中的方法(库中的JdbcTemplate会知道该外部事务)。 So I need to create JdbcTemplate so that it will ignore outer transactions. 因此,我需要创建JdbcTemplate,以便它将忽略外部事务。 Is that possible? 那可能吗?

So Application transaction propagation level shouldn't effect your library transaction management, is this my understanding correct? 因此,应用程序事务传播级别不应影响您的库事务管理,这对我的理解正确吗?

If Yes, you may have a look at Propagation.NOT_SUPPORTED , ref 如果是,则可以查看Propagation.NOT_SUPPORTED参考

I believe you are going to design interface in your library which will expose public methods used by application, what if all interface method annotated with @Transactional(propagation = Propagation.NOT_SUPPORTED) ? 我相信您将在库中设计接口,该接口将公开应用程序使用的公共方法,如果所有接口方法都用@Transactional(propagation = Propagation.NOT_SUPPORTED)注释,该怎么办? wouldn't it solve your problem. 它不能解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM