【发布时间】:2018-01-23 15:28:51
【问题描述】:
我在 Spring 启动应用程序中使用带有 @ContextConfiguration 的 RestTemplateBuilder 时遇到了问题(我尝试添加 @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>()
【问题讨论】:
-
您找到解决方案了吗?
标签: spring-boot integration-testing resttemplate spring-test context-configuration