Spring?Boot2.6.0新特性之默認(rèn)禁止循環(huán)引用
前言
如下代碼,ComponentA類(lèi)注入ComponentB類(lèi),ComponentB類(lèi)注入ComponentA類(lèi),就會(huì)發(fā)生循環(huán)依賴(lài)的問(wèn)題,在2.6.0之前,spring會(huì)自動(dòng)處理循環(huán)依賴(lài)的問(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)文章
淺談Java線(xiàn)程并發(fā)知識(shí)點(diǎn)
本文主要對(duì)Java線(xiàn)程并發(fā)的知識(shí)點(diǎn)進(jìn)行簡(jiǎn)單介紹。具有很好的參考價(jià)值,需要的朋友一起來(lái)看下吧2016-12-12基于java下載中g(shù)etContentLength()一直為-1的一些思路
下面小編就為大家?guī)?lái)一篇基于java下載中g(shù)etContentLength()一直為-1的一些思路。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-06-06Spring事件發(fā)布監(jiān)聽(tīng),順序監(jiān)聽(tīng),異步監(jiān)聽(tīng)方式
這篇文章主要介紹了Spring事件發(fā)布監(jiān)聽(tīng),順序監(jiān)聽(tīng),異步監(jiān)聽(tīng)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12JSP頁(yè)面pageEncoding和contentType屬性
有關(guān)于JSP頁(yè)面中pageEncoding和contentType屬性。2013-04-04springboot控制層傳遞參數(shù)為非必填值的操作
這篇文章主要介紹了springboot控制層傳遞參數(shù)為非必填值的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-10-10multi-catch和try-catch異常處理知識(shí)點(diǎn)詳解
在本篇文章里我們給大家分享了一篇關(guān)于multi-catch和try-catch異常處理知識(shí)點(diǎn)內(nèi)容,有需要的朋友們可以參考學(xué)習(xí)下。2019-11-11