VanRoy/spring-data-jest

I am unable to use an embedded elasticsearch with spring boot

Closed this issue · 3 comments

I am trying to start a project with an embedded elasticsearch. I am getting the following exception
Caused by: com.github.vanroy.springdata.jest.exception.JestElasticsearchException: Cannot execute jest action , response code : 500 , error : {"root_cause":[{"type":"class_cast_exception","reason":"org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext"}],"type":"class_cast_exception","reason":"org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext"}

`
<java.version>1.8</java.version>
<kotlin.version>1.3.50</kotlin.version>
<h2.version>1.4.199</h2.version>
<mapstruct.version>1.3.1.Final</mapstruct.version>
<jaxb-runtime.version>2.3.2</jaxb-runtime.version>
<org.apache.maven.plugins.version>3.6.0</org.apache.maven.plugins.version>
<problem-spring-web.version>0.25.0</problem-spring-web.version>
<springfox-swagger-ui.version>2.8.0</springfox-swagger-ui.version>
<hazelcast.version>3.11.4</hazelcast.version>
<hazelcast-hibernate53.version>1.3.2</hazelcast-hibernate53.version>
<log4j2-mock.version>0.0.1</log4j2-mock.version>
<spring-data-jest.version>3.3.0.RELEASE</spring-data-jest.version>

<dependencies>
    <!--<dependency>-->
        <!--<groupId>org.springframework.boot</groupId>-->
        <!--<artifactId>spring-boot-starter-security</artifactId>-->
    <!--</dependency>-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-cache</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
    </dependency>
    <!-- jest dependencies -->

    <dependency>
        <groupId>com.github.vanroy</groupId>
        <artifactId>spring-boot-starter-data-jest</artifactId>
        <version>${spring-data-jest.version}</version>
    </dependency>
    <!-- log4j2-mock needed to create embedded elasticsearch instance with SLF4J -->

    <!-- Only required for start local ES node -->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <scope>compile</scope>
    </dependency>

    <!-- jest dependencies -->

    <dependency>
        <groupId>com.fasterxml.jackson.module</groupId>
        <artifactId>jackson-module-kotlin</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-reflect</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib-jdk8</artifactId>
    </dependency>
    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-core</artifactId>
    </dependency>
    <dependency>
        <groupId>com.hazelcast</groupId>
        <artifactId>hazelcast</artifactId>
    </dependency>
    <dependency>
        <groupId>com.hazelcast</groupId>
        <artifactId>hazelcast-spring</artifactId>
    </dependency>
    <dependency>
        <groupId>com.hazelcast</groupId>
        <artifactId>hazelcast-hibernate53</artifactId>
    </dependency>

    <dependency>
        <groupId>org.zalando</groupId>
        <artifactId>problem-spring-web</artifactId>
        <version>${problem-spring-web.version}</version>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>${springfox-swagger-ui.version}</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>${springfox-swagger-ui.version}</version>
    </dependency>

    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct</artifactId>
        <version>${mapstruct.version}</version>
    </dependency>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-processor</artifactId>
        <version>${mapstruct.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>${h2.version}</version>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>`

Forgot to add the spring version

org.springframework.boot
spring-boot-starter-parent
2.2.1.RELEASE

Hi @tmdonalds , it's probably due to an dependencies conflict.

Can you send a sample project to reproduce ?

If you requirement is for testing maybe you can evaluate to migrate from embedded ES to Testcontainers : https://www.testcontainers.org/modules/elasticsearch/

Julien.

Thanks for the update @VanRoy . Actually such a simple mistake. I realized that when I was trying to build. I did not use mvn clean ...I used mvn clean and the problem went away. Thanks for your assistance