取代@autowed to Springboot的私人决赛不为Service工作。

问题描述 投票:0回答:2
我在这里阅读:

https://medium.com/@dulanjayasandaruwan1998/spring-doesnt-recommend-autowiled-autowiled-anymore-05fc053099dadd 基本上可以将其删除,然后将其替换为@Autowired

private final
,无论如何,我尝试将其用于repo,它正在工作,但它不起作用。它有这样的错误:

@Service
@RequiredArgsConstructor
public class MyService {

    private final MyRepository myRepository;
}
我想做的概念是:

Action: Despite circular references being allowed, the dependency cycle between beans could not be broken. Update your application to remove the dependency cycle.
在删除

@Service @RequiredArgsConstructor public class AnotherService { private final MyService myService; } @Service @RequiredArgsConstructor public class MyService { private final AnotherService anotherService; }

时,我有什么办法可以使它起作用。
    

您可以使用
@Autowired

注释来懒洋洋地注入豆类,从而避免循环依赖。 建议在构造仪注入中。
spring-boot lombok
2个回答
0
投票

添加

@Lazy
或使用

spring.main.allow-circular-references=true

0
投票
@Lazy

ApplicationContext
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.