在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ springboot 在一個Service類的方法上用異步注解@Async,啟動

springboot 在一個Service類的方法上用異步注解@Async,啟動就報循環(huán)依賴錯誤

我只要在directoryProcurementApplyServiceImpl這個類中的一個方法上加上@Async,啟動就報錯。

The dependencies of some of the beans in the application context form a cycle:

| ESInitController (field private com.zhichubao.core.service.p2p.payables.PayablesService com.zhichubao.web.api.ESInitController.payablesService)
↑ ↓
| payablesServiceImpl (field private com.zhichubao.core.service.common.CommonService com.zhichubao.core.service.p2p.payables.impl.PayablesServiceImpl.commonService)
↑ ↓
| commonServiceImpl (field private com.zhichubao.core.service.p2p.procurement.DirectoryProcurementApplyService com.zhichubao.core.service.common.impl.CommonServiceImpl.directoryProcurementApplyService)
↑ ↓
| directoryProcurementApplyServiceImpl
└─────┘

但是我在controller中用過異步注解很多次都沒報錯,放到service上的方法上就報錯,什么原因呢?

回答
編輯回答
糖豆豆

在你循環(huán)依賴的兩個bean的任意一個上加上lazy-init屬性試試。
例如:

@Autowired
@Lazy
private Test test; 
2017年1月31日 01:13