简体   繁体   中英

java.lang.NoSuchMethodError when running SoapUIMockServiceRunner

Ran into an issue while running a SoapUI MockService in my integration tests for our Spring Boot project.

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();
}

Gave me this error when running:

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)

Seemed to be issue with org.apache.log4j.ConsoleAppender class version coming in from log4j-over-slf4j dependency, which was quite empty.

mvn dependency:tree showed the dependency came in from 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

Adding an exclusion to that dependency solved it for me:

    <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>

I hope this helps someone, someday.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM