【发布时间】:2022-01-24 00:20:38
【问题描述】:
按照这个post,我配置了
(1) 一个 Eureka 服务器,
(2) 作为 (1) 的客户的收费服务,
(3) 从 (2) 读取数据的收费率仪表板。
在我使用@LoadBalanced 进行一些更改之前一切顺利(也许这不完全是由于负载平衡器,但我将在下面发布相关代码块)
(2)中的bootstrap.properties中,公共端点名称为
spring.application.name = demo-tollrate-service
在(3)中的DashboardController.java中,可以看到HTTP地址改成了上面的应用名
// import some libraries
@Controller
public class DashboardController {
@Autowired
private RestTemplate restTemplate;
@LoadBalanced
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}
@RequestMapping("/dashboard")
public String GetTollRate(@RequestParam int stationId, Model m) {
TollRate tr = restTemplate.getForObject("http://demo-tollrate-service/tollrate/" + stationId, TollRate.class);
m.addAttribute("rate", tr.getCurrentRate());
return "dashboard";
}
}
这个post中的pom.xml大致相同
运行此应用时,出现以下错误。
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
┌──->──┐
| dashboardController (field private org.springframework.web.client.RestTemplate com.example.demo.DashboardController.restTemplate)
└──<-──┘
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.
有人可以帮我吗?谢谢。
【问题讨论】:
-
你试过用-debug运行吗?
-
它给出了同样的错误信息
标签: spring spring-boot load-balancing resttemplate