Spring?Boot2.6.0新特性之默認(rèn)禁止循環(huán)引用
前言
如下代碼,ComponentA類注入ComponentB類,ComponentB類注入ComponentA類,就會(huì)發(fā)生循環(huán)依賴的問(wèn)題,在2.6.0之前,spring會(huì)自動(dòng)處理循環(huán)依賴的問(wèn)題
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class ComponentA {
@Resource
private ComponentB componentB;
}import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class ComponentB {
@Resource
private ComponentA componentA;
}現(xiàn)在,2.6.0 這個(gè)版本已經(jīng)默認(rèn)禁止 Bean 之間的循環(huán)引用,如果存在循環(huán)引用就會(huì)啟動(dòng)失敗報(bào)錯(cuò):
***************************
APPLICATION FAILED TO START
***************************Description:
The dependencies of some of the beans in the application context form a cycle:
┌─────┐
| componentA
↑ ↓
| componentB
└─────┘
Action:Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.
處理方案一:
整改業(yè)務(wù),清理掉所有存在循環(huán)引用的 Bean
處理方案二:
spring:
main:
allow-circular-references: true
處理方案三:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringDemoApplication {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(SpringDemoApplication.class);
application.setAllowCircularReferences(Boolean.TRUE);
application.run(args);
}
}總結(jié)
到此這篇關(guān)于Spring Boot2.6.0新特性之默認(rèn)禁止循環(huán)引用的文章就介紹到這了,更多相關(guān)SpringBoot2.6.0默認(rèn)禁止循環(huán)引用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Tomcat使用IDEA遠(yuǎn)程Debug調(diào)試的講解
今天小編就為大家分享一篇關(guān)于Tomcat使用IDEA遠(yuǎn)程Debug調(diào)試的講解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03
springboot application無(wú)法使用$獲取pom變量的問(wèn)題及解決
這篇文章主要介紹了springboot application無(wú)法使用$獲取pom變量的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02
MybatisPlus調(diào)用原生SQL的三種方法實(shí)例詳解
這篇文章主要介紹了MybatisPlus調(diào)用原生SQL的三種方法,在有些情況下需要用到MybatisPlus查詢?cè)鶶QL,MybatisPlus其實(shí)帶有運(yùn)行原生SQL的方法,我這里列舉三種,需要的朋友可以參考下2022-09-09
Java面向?qū)ο蠡A(chǔ)知識(shí)之封裝,繼承,多態(tài)和抽象
這篇文章主要介紹了Java面向?qū)ο蟮姆庋b,繼承,多態(tài)和抽象,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)java基礎(chǔ)的小伙伴們有很好的幫助,需要的朋友可以參考下2021-11-11

