使用RestTemplateBuilder和@ContextConfiguration在Spring Boot应用程序中遇到了问题(我尝试添加@SpringBootTest,@RunWith(SpringRunner.class)注释,但没有任何运气)。
非常感谢您的帮助。下面是背景:
我已经像以下方式注释了我的类:
@ContextConfiguration(classes = {
JsonNodeList.class,
JsonNodeUtils.class,
MyService.class,
RestClient.class,
RestTemplateBuilder.class}, loader = SpringBootContextLoader.class)
public class StepsDefinition {
RestClient 类已经自动装配了 RestTemplateBuilder,如下所示:
@Autowired
public RestClient(final RestTemplateBuilder restTemplateBuilder) {
this.restTemplate = configureRestTemplate(restTemplateBuilder);
}
MyService类自动装配RestClient。当我尝试使用@ContextConfiguration
和SpringBootContextLoader
加载应用程序时,出现以下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restTemplateBuilder': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.client.RestTemplateBuilder]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.springframework.boot.web.client.RestTemplateBuilder.<init>()