运行SoapUIMockServiceRunner时出现java.lang.NoSuchMethodError

时间:2017-11-29 14:18:44

标签: java spring-boot soapui spring-boot-test

在我的Spring Boot项目的集成测试中运行SoapUI MockService时遇到问题。

static SoapUIMockServiceRunner mockServiceRunner;

@BeforeClass
public static void setupSoapUI(){
    mockServiceRunner = new SoapUIMockServiceRunner();
    mockServiceRunner.setProjectFile("src/test/resources/MyRESTMockService-soapui-project.xml");
    mockServiceRunner.setMockService("MyRESTMockService");
    mockServiceRunner.setBlock(false);
    try {
        mockServiceRunner.run();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

@AfterClass
public static void tearDownSoapUI(){
    mockServiceRunner.stopAll();
}

运行时给我这个错误:

java.lang.NoSuchMethodError: org.apache.log4j.ConsoleAppender.setWriter(Ljava/io/Writer;)V

    at com.eviware.soapui.tools.AbstractSoapUIRunner.ensureConsoleAppenderIsDefined(AbstractSoapUIRunner.java:96)
    at com.eviware.soapui.tools.AbstractSoapUIRunner.initGroovyLog(AbstractSoapUIRunner.java:77)
    at com.eviware.soapui.tools.SoapUIMockServiceRunner.runRunner(SoapUIMockServiceRunner.java:90)
    at com.eviware.soapui.tools.AbstractSoapUIRunner.run(AbstractSoapUIRunner.java:202)

1 个答案:

答案 0 :(得分:1)

似乎是来自log4j-over-slf4j依赖的org.apache.log4j.ConsoleAppender类版本的问题,这是非常空的。

mvn dependency:tree显示依赖来自boot:spring-boot-starter-web

[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.5.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.2.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.5.2.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.2.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.2.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.24:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.24:compile

为该依赖项添加排除项为我解决了这个问题:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>log4j-over-slf4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

我希望有一天能帮助别人。