创建lombok依赖unable to find valid certification path to requested target
时间: 2023-09-21 13:11:49 浏览: 143
在Spring Boot项目中,如果使用RestTemplate调用https接口时出现"unable to find valid certification path to requested target"的错误,可能是由于缺少证书导致的。这个错误通常发生在RestTemplate在尝试建立与目标服务器的安全连接时无法验证服务器的证书。
要解决这个问题,可以按照以下步骤进行操作:
1. 首先,确保你的项目中已经添加了Lombok依赖。Lombok是一个Java库,可以通过简化一些常见的任务来减少代码量。
2. 确保你的项目中的pom.xml文件中已经添加了Lombok依赖项。可以在pom.xml中添加以下代码来引入Lombok依赖:
```xml
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
```
3. 当使用RestTemplate调用https接口时,可以尝试在代码中使用静态方法的形式去调用RestTemplate,并且设置合适的请求头和请求体。具体代码如下所示:
```java
HttpHeaders headers = new HttpHeaders();
headers.set("xxx", "123");
headers.set("xxx","456");
headers.set("Content-Type","text/plain");
HttpEntity<String> body = new HttpEntity<>("请求体字符串", headers);
ResponseEntity<String> response = RestTemplateUtil.getRestTemplate(timeout).postForEntity(sendUrl, body, String.class);
```
通过以上步骤,你可以解决创建Lombok依赖时出现的"unable to find valid certification path to requested target"错误。这样你就可以在Spring Boot项目中正常使用RestTemplate来调用https接口了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [unable to find valid certification path to requested target](https://blog.csdn.net/y_bccl27/article/details/111358091)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [javax.mail 邮件unable to find valid certification path to requested target](https://blog.csdn.net/wnsh1990/article/details/128875221)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文