cjstehno / ersatz

🤖 A simulated HTTP server for testing client code with configurable responses.
https://cjstehno.github.io/ersatz
Apache License 2.0
47 stars 5 forks source link

ClassNotFoundException when add the Erstaz 1.6.2 dependency in a 1.5.9 Spring Boot project #92

Closed MiguelAngel82 closed 6 years ago

MiguelAngel82 commented 6 years ago

Hello all. When the Erstaz 1.6.2 dependency is added in a 1.5.9 Spring Boot project, and the integration tests are executed, the following error is thrown:

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'undertowEmbeddedServletContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration$EmbeddedUndertow.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory]: Factory method 'undertowEmbeddedServletContainerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: io/undertow/servlet/api/SessionPersistenceManager
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
[...]
Caused by: java.lang.ClassNotFoundException: io.undertow.servlet.api.SessionPersistenceManager
[...]

The dependency is added in the pom.xml file:

        <dependency>
            <groupId>com.stehno.ersatz</groupId>
            <artifactId>ersatz</artifactId>
            <version>0.4.3</version>
        </dependency>

I've also tried other versions of Ersatz, but the same error is thrown. Somebody knows what could be the problem?

Thanks in advance!

Regards, Miguel.

cjstehno commented 6 years ago

Are you using undertow as your server in boot? If so, you should use the shaded "safe" version of the library. See the user guide help section.

cjstehno commented 6 years ago

Also, assuming that pom snippet is wrong. That's a really old version.

MiguelAngel82 commented 6 years ago

Uhm, I'm not sure if "undertow" is being used in the project, maybe as a result of another dependecy...

Here is the complete pom file (regarding dependencies):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    [...]
    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-ws-security</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-ws-policy</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-ws-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
            <version>1.4.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.icegreen</groupId>
            <artifactId>greenmail</artifactId>
            <version>1.5.7</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>1.7</version>
        </dependency>
        <dependency>
            <groupId>com.stehno.ersatz</groupId>
            <artifactId>ersatz</artifactId>
            <version>1.6.2</version>
        </dependency>
    </dependencies>
    <properties>
        <cxf.version>3.1.14</cxf.version>
    </properties>
</project>
cjstehno commented 6 years ago

Oh... so you are not really using boot as an application, just a library. I would still suggest trying the safe shaded library (http://stehno.com/ersatz/asciidoc/html5/#_shadow_jar).

Also, check your generated classpath and make sure that there is at least one undertow library... maybe it is not being pulled in properly for some reason. If there are is more than one present you'll need to use the shadow jar or figure out where the other undertow is coming from and exclude it.

I have used Ersatz with spring and spring boot without issues, so I know it should work.

cjstehno commented 6 years ago

Were you able to resolve this issue?

MiguelAngel82 commented 6 years ago

Hi @cjstehno.

I'm so sorry for the delay in my response. Unfortunately I've been move on another project, so I couldn't try your suggested solution (which I think is the best solution).

Anyway, thank you very much for your help and I'll close this issue. If anyone has a similar problem at any time, it could be helpful.

Thanks again!

Regards, Miguel.