Unexpected error: java.security.InvalidAlgorithmParameterException
1. 异常信息
Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty executing POST https://xxxx/v1/corp/createcorp] with root cause fegin
2. 自定义 Feign 客户端以忽略 HTTPS 证书验证
这个错误提示说明在执行 HTTPS 请求时,Java 虚拟机无法找到任何可信任的根证书来验证服务器的 SSL 证书。这通常发生在 SSL 握手阶段,当客户端尝试建立与服务器的安全连接时。
错误发生在执行 POST 请求到 https://xxx/v1/corp/createcorp,这很可能是一个调用服务(如果这是正确的服务地址)的API。
import feign.Client;
import feign.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
/**
* feign 日志基本配置
*/
@Configuration
public class FeignConfig {
@Bean
public Client feignClient() throws NoSuchAlgorithmException, KeyManagementException {
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[]{};
}
}
};
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// 创建一个Client.Default实例,它接受一个SSLSocketFactory和一个HostnameVerifier
return new Client.Default(sslContext.getSocketFactory(), (hostname, session) -> true);
}
}
3. feign 配置
@FeignClient(name = "tt", url = "${cc.url}")
public interface TtClient {
@PostMapping("/v1/corp/createcorp")
JSONObject createcorp(@RequestBody JSONObject body);
}
286

被折叠的 条评论
为什么被折叠?



