循環(huán)依賴:
循環(huán)依賴就是循環(huán)引用,也就是兩個或則兩個以上的bean互相依賴對方,形成閉環(huán)。比如A類中有B屬性,B類中有A屬性
一、報(bào)錯信息
The dependencies of some of the beans in the application context form a cycle:
?二、解決方案
1、修改配置文件
根據(jù)Action中的提示
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.
不鼓勵依賴循環(huán)引用,默認(rèn)情況下禁止循環(huán)引用。更新應(yīng)用程序以刪除 Bean 之間的依賴關(guān)系循環(huán)。作為最后的手段,可以通過將 spring.main.allow-circular-references 設(shè)置為 true 來自動打破循環(huán)。因此可以在yml配置文件中設(shè)置來打破循環(huán)依賴
修改yml
spring:
main:
allow-circular-references: true
2、添加注解,延遲加載
這個是網(wǎng)上找到的解決方案,經(jīng)過測試,問題順利解決
由于在循環(huán)依賴中,Spring在初始化的時候不知道先加載哪個bean,因此可以通過使用@Lazy注解,放在其中一個bean上,讓這個bean延遲加載,另一個bean就會先加載,進(jìn)而解決循環(huán)依賴問題文章來源:http://www.zghlxwxcb.cn/news/detail-510689.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-510689.html
到了這里,關(guān)于SpringBoot中循環(huán)依賴報(bào)錯解決---The dependencies of some of the beans in the application context form a cycle的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!