java - TestRestTemplate - 从 Spring Boot 1.5 迁移到 2.0

标签 java spring spring-boot

当我将我的代码库从 spring boot 1.5 迁移到 2.0 时 - 我遇到了 1.5 测试中的这个构造函数已在 2.0 中完全删除。 & 它们似乎不是 Spring Boot 2.0 中的替代品?

TestRestTemplate template = new TestRestTemplate(restTemplate.getRestTemplate(),"用户名","密码");

类别: org.springframework.boot.test.web.client.TestRestTemplate

谢谢

最佳答案

现在需要传递 RestTemplateBuilder 而不是 RestTemplate

https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/web/client/TestRestTemplate.html

TestRestTemplate(RestTemplateBuilder restTemplateBuilder, String username, String password, TestRestTemplate.HttpClientOption... httpClientOptions) Create a new TestRestTemplate instance with the specified credentials.

关于java - TestRestTemplate - 从 Spring Boot 1.5 迁移到 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51895726/

相关文章:

java - Hibernate createSqlQuery 设置变量

java - 来自 Ionic 应用程序的 https 请求第一次返回 403 然后它就可以工作了

java - 将 .pem 转换为 jks,无需 key 文件

java - 即使具有 transient ApplicationContext UI 的成员,XmlWebApplicationContext 的 Vaadin Spring Addon NotSerializedException

java - 重复关注 javax.validation.constraints 和 javax.persistence.Column

Spring Batch - 提交间隔的后期绑定(bind)不适用于跳过策略

java - 将 SSL 添加到 Spring Boot 应用程序

java - SpringController 中的自定义 json 返回

java - Kotlin协程vs CompletableFuture

Java Swing,所有图像均出现像素化