无法初始化 class com.github.tomakehurst.wiremock.core.WireMockApp

Could not initialize class com.github.tomakehurst.wiremock.core.WireMockApp

我最近将我的 Java 版本升级到 Java11 for 8,从那以后我看到了这个错误:

java.lang.NoClassDefFoundError: Could not initialize class com.github.tomakehurst.wiremock.core.WireMockApp

at com.github.tomakehurst.wiremock.WireMockServer.(WireMockServer.java:73) at com.github.tomakehurst.wiremock.WireMockServer.(WireMockServer.java:112)

下面是我对 wiremock 的用法:

@RunWith(PowerMockRunner.class)
@PrepareForTest(ConfigManagement.class)
@PowerMockIgnore({"javax.management.*","com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*","com.github.tomakehurst.*"})
public class MandateEventsJobTest {

    private static HikariDataSource dataSource;
    private WireMockServer wireMockServer;

    @Before
    public void setUp() throws Exception {
        wireMockServer = new WireMockServer(8080);
        wireMockServer.start();
        stubFor(get(urlPathMatching("/ping")).willReturn(aResponse().withBody("pong")));

...

我无法解决这个问题。请帮忙。

似乎 java 版本 9 或更高版本中的 PowerMockRunner 存在问题。我向 @PowerMockIgnore({}) 添加了更多的包并且它起作用了:

@PowerMockIgnore({"javax.management.","com.sun.org.apache.xerces.", "javax.xml.", "org.xml.", "com.sun.org.apache.xalan.", "javax.net."})