如何制作RestTemplateBuilder的副本?

时间:2019-07-15 12:09:21

标签: spring-boot resttemplate

我想为所有RestTemplate实例使用一种基本配置。

我创建了RestTemplateProvider,它从Spring Boot中获得了RestTemplateBuilder,并设置了适当的超时时间和其他选项。

问题是-我如何克隆RestTemplateBuilder以防止在使用它的地方对其进行修改?

1 个答案:

答案 0 :(得分:1)

如果您查看RestTemplateBuilder的来源,您会注意到,每次更改设置都会创建一个 String threeWay; String doubleChance; String goalGoal; String halfTime; String bookingPts 的新实例。

因此,您想要的东西基本上已经开箱即用地嵌入到RestTemplateBuilder中。