SSLContext.getInstance中的NoSuchAlgorithmException

时间:2017-08-24 10:41:58

标签: java ssl

我在以下代码中收到NoSuchAlgorithmException

 @RunWith(PowerMockRunner.class)
 @PrepareForTest({CloudWatchHelper.class})
 class MyTest {
 ....
 final SSLContext sslcontext = SSLContext.getInstance("TLS");
 ...
 }

堆栈追踪:

[junit] class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext
[junit] java.security.NoSuchAlgorithmException: class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext
[junit]     at sun.security.jca.GetInstance.checkSuperClass(GetInstance.java:260)
[junit]     at sun.security.jca.GetInstance.getInstance(GetInstance.java:237)
[junit]     at sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
[junit]     at javax.net.ssl.SSLContext.getInstance(SSLContext.java:156)

我想知道NoSuchAlgorithmException背后的原因是什么。

2 个答案:

答案 0 :(得分:0)

在我的测试类中添加以下批注为我解决了此问题:

@PowerMockIgnore({ "javax.net.ssl.*", "javax.security.*" })

答案 1 :(得分:-1)

我意识到因为以下原因我得到了例外:

 @RunWith(PowerMockRunner.class)
 @PrepareForTest({CloudWatchHelper.class})