0

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

java.lang.NoClassDefFoundError:无法初始化类 com.github.tomakehurst.wiremock.core.WireMockApp

在 com.github.tomakehurst.wiremock.WireMockServer.(WireMockServer.java:73) 在 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")));

...

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

4

1 回答 1

0

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

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

于 2021-12-16T10:55:04.437 回答