How to Solve creating bean with name ‘mappingjackson2httpmessageconverter’ error when elasticsearch advanced client starts‘

When learning elasticsearch, write the code to ehcahce index. When starting the project, an error is reported in the error creating bean with name ‘mappingjackson2httpmessageconverter’.

So I looked for the jar package in lib and found that Jackson’s package was introduced. However, no dependency is introduced into the POM file. I checked the related dependencies and found that they were introduced from the high-level client

It seems to be a necessary package for elastic advanced client. To test this conjecture, I deleted all the jar packages of Jackson and started it. The project did start successfully, but an error occurred when sending the index request, that is, in this line of code indexrequest.Source (JSON).

It seems that it is a necessary package. But I didn’t find the right answer on the Internet. To solve this problem, I manually introduced Jackson into

Then delete all the jar packages that do not belong to my imported Jackson.
the red box part is the jar package I manually imported, and the blue part is the jar package automatically imported by the advanced client. Manually delete the jar package in blue. The measured items can be started normally and the index request can be sent

However, there is a fatal problem, that is, if reload maven, the jar package in the blue part will be automatically introduced. To solve this problem, we must first find out which jar packages are introduced into our POM file, and then ignore these jar packages using the exclusion method. Finally, my POM file is shown below


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.3.12.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>com.fasterxml.jackson.datatype</groupId>
                    <artifactId>jackson-datatype-jdk8</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.datatype</groupId>
                    <artifactId>jackson-datatype-jsr310</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.2.1</version>
            <exclusions>
                <exclusion>
                    <groupId>com.fasterxml</groupId>
                    <artifactId>jackson-xml-databind</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.dataformat</groupId>
                    <artifactId>jackson-dataformat-smile</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.dataformat</groupId>
                    <artifactId>jackson-dataformat-yaml</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.dataformat</groupId>
                    <artifactId>jackson-dataformat-cbor</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- json包 -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>
    </dependencies>

Read More: