我使用Rest模板创建Rest Web服务调用,对于基本身份验证,我尝试使用RestTemplateBuilder在发送请求时构建基本身份验证。我给出了所有的spring boot依赖项:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
代码:
final RestTemplate restTemplate = restTemplateBuilder
.basicAuthorization("username", "password").build();
restTemplate.postForObject("rest webservice url",inputparam, XXX.Class);
但是,即使在提供了依赖项之后,构建也会失败。有人能在这方面帮我吗?
https://stackoverflow.com/questions/50748358
复制相似问题