SpringBootTest 导致 jenkins 上的非法状态异常

问题描述

按照此处 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

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)