首页 > 解决方案 > SpringBootTest 在詹金斯上导致非法状态异常

问题描述

按照此处https://spring.io/guides/gs/testing-web/的说明进行了我们的 Spring Boot 应用程序和测试设置,例如

@SpringBootTest
class ApisApplicationTests {

    @Test
    void contextLoads() {
    }

}

@SpringBootTest
class SonarQubeClientTest {

    @Autowired
    private SonarQubeClient sonarQubeClient;

    @Autowired
    private RestTemplate restTemplate;

    private MockRestServiceServer mockServer;

    @BeforeEach
    public void init() {
        mockServer = MockRestServiceServer.createServer(restTemplate);
    }

    @Test
    void deleteProject() throws Exception {
        mockServer.expect(ExpectedCount.once(),
                requestTo(new URI("https://sonar-prod.xxxxxxxxxx.int/api/projects/delete")))
                .andExpect(method(HttpMethod.POST))
                .andRespond(withStatus(HttpStatus.NO_CONTENT));
        sonarQubeClient.deleteProject("fake-service");
        mockServer.verify();
    }
}

gradle 在本地构建完美,但由于某种原因,在 jenkins 上构建时,我们不断遇到上述测试的相同失败:

java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
        Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:798
            Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:798
                Caused by: org.springframework.beans.factory.BeanCreationException at ConstructorResolver.java:314
                    Caused by: org.springframework.beans.BeanInstantiationException at BeanUtils.java:216
                        Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException at DataSourceUtils.java:82
                            Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException at SQLError.java:174
                                Caused by: com.mysql.cj.exceptions.CJCommunicationsException at NativeConstructorAccessorImpl.java:-2
                                    Caused by: javax.net.ssl.SSLHandshakeException at HandshakeContext.java:170

有人可以帮忙吗?提前谢谢。

标签: jenkinsspring-boot-test

解决方案


推荐阅读