gpt4 book ai didi

java - PowerMock AmazonS3Client 配置问题

转载 作者:搜寻专家 更新时间:2023-10-31 20:09:11 26 4
gpt4 key购买 nike

我在尝试使用 PowerMock 运行模拟测试时得到了这个堆栈

 Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.amazonaws.services.s3.AmazonS3Client]: Factory method   'amazonS3Client' threw exception; nested exception is org.apache.http.conn.ssl.SSLInitializationException: class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext
Caused by: org.apache.http.conn.ssl.SSLInitializationException: class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext
Caused by: java.security.NoSuchAlgorithmException: class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext

我尝试过使用 org.apache.http.con.ssl.* 添加 @PowerMockIgnore 的建议,但这样做会导致我的 Rabbit 连接器失败。我不确定是否有任何建议对我的测试都有负载。或者如果测试不需要,则不初始化一个?

我能提供的东西有限,因为这是我公司的事情。

使用亚马逊 SDK:1.11.69

这是我配置测试的方式

@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations={"classpath:applicationContext-test.xml"})
@TestExecutionListeners(listeners={ServletTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
TransactionalTestExecutionListener.class,
WithSecurityContextTestExecutionListener.class})
@PrepareForTest({Observable.class,HardDeleteUserCommand.class,SoftDeleteUserCommand.class})
@PowerMockIgnore({ "javax.management.*", "ch.qos.logback.*",
"org.slf4j.*" })

示例 Bean:

@Configuration
@Profile("Test")
public class S3Configuration {
@Bean
public AmazonS3Client amazonS3Client() throws IOException {
return new AmazonS3Client(new EnvironmentVariableCredentialsProvider());
}
}

最佳答案

正如@srkavin 在评论中所说,当我添加 @PowerMockIgnore({ "javax.net.ssl.*"})

时,此错误消失了

关于java - PowerMock AmazonS3Client 配置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41271112/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com