简体   繁体   English

在Spring Boot应用程序中禁用事务管理器

[英]Disable transaction manager in Spring Boot application

How to disable transaction manager in Spring Boot application? 如何在Spring Boot应用程序中禁用事务管理器?

I have this exception : 我有这个例外:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.transaction.PlatformTransactionManager] is defined

Because of @Transactional annotations (I use these annotations in an other app, so I can't remove, but there is a way to ignore it? By disable transaction manager?). 由于@Transactional注释(我在其他应用程序中使用了这些注释,因此无法删除,但是有一种方法可以忽略它?通过禁用事务管理器?)。

I guess you have three choices: 我猜您有三种选择:

  1. remove the annotation 删除注释

  2. supply a transaction manager 提供交易经理

  3. exclude the configuration class that adds @EnableTransactionManagement 排除添加@EnableTransactionManagement的配置类

In a Spring Boot app you only get @EnableTransactionManagement if you are using JDBC or JPA, so really there should be a transaction manager already. 在Spring Boot应用程序中,如果您使用的是JDBC或JPA,则只会获得@EnableTransactionManagement ,因此实际上应该已经有一个事务管理器。 The only reason I can see for one not being there is you have spring-jdbc on the classpath but no database. 我能看到的唯一原因就是您在类路径上有spring-jdbc却没有数据库。 If you have spring-tx and spring-jdbc on your classpath already (which seems to be the case) you can just add an in-memory database (eg h2) to get a transaction manager. 如果您的类路径上已经有spring-tx和spring-jdbc(似乎是这种情况),则只需添加内存数据库(例如h2)即可获得事务管理器。 That seems like the best solution to me. 这对我来说似乎是最好的解决方案。 But you could also exclude DataSourceTransactionManagerAutoConfiguration in your @EnableAutoConfiguration . 但是您也可以在@EnableAutoConfiguration排除DataSourceTransactionManagerAutoConfiguration

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

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