SpringBoot2中关于重复创建bean的问题解决

今天在跑程序的时候报了一个重复创建事务的异常:

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'org.springframework.transaction.config.internalTransactionAdvisor', defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class], could not be registered. A bean with that name has already been defined and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

是ProxyTransactionManagementConfiguration.class这个bean在创建时重复了,springboot的自动装配和我的程序同时创建了相同类型的bean。之所以报这个异常是因为在Spring2中增加了防止bean重复覆盖的策略,如果有重复则会直接报出异常,而不是像从前一样默默覆盖,导致你的bean被莫名替换,难以排查问题。stackoverflow上的解答如下:

SpringBoot2中关于重复创建bean的问题解决_第1张图片

原文地址:https://stackoverflow.com/questions/51367566/trouble-when-changing-spring-boot-version-from-2-0-3-release-to-2-1-0-build-snap

 

我这边程序的解决方案是忽略spring的自动装配,禁止TransactionAutoConfiguration即可:

@SpringBootApplication(exclude = TransactionAutoConfiguration.class)

 

你可能感兴趣的:(异常恩仇录,springboot,transaction)