JAVA开发遇到的异常-java.lang.SecurityException: JCE cannot authenticate the provider SunJCE
问题背景:为了获取小程序全局唯一后台接口调用凭据(access_token)需要通过后台发送GET请求
GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
public static String sendGet(String url) {
String result = "";
BufferedReader in = null;
try {
//String urlNameString = url + "?" + param;
System.out.println("发送的链接请求:" + url);
URL reaurl = new URL(url);
URLConnection connection = reaurl.openConnection();
// 设置通用
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 建立实际的连接
connection.connect();
Map<String, List<String>> map = connection.getHeaderFields();
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送GET请求出现异常!" + e);
e.printStackTrace();
}
// 使用finally块来关闭输入流
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result;
}
后台报出的异常信息
2021-03-17 19:48:02.884 ERROR com.wenyi.core.comm.http.HttpClientUtil 616 a - HttpGet Error: javax.net.ssl.SSLException: java.lang.SecurityException: JCE cannot authenticate the provider SunJCE

SSLHandshakeException:Could not generate secret

解决过程
首页通过
进行验证接口是否正确;
发现无误后,估计是jdk有问题,猜测在eclipse中运行时,把签名信息给去掉了,于是恢复下jdk
先找到Installed JREs->选择jdk->Edit

在JRE Definition下直接Restore Default

恢复后测试下,如果还不行,检查运行的tomcat是否调用的是刚恢复的JRE
