Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring web mvc example, boot, Error creating bean with name 'jacksonObjectMapperBuilder'

I'm new to Spring and largely to Java beyond the language itself...minimal console apps, etc. I'm trying to get the Spring website example here (https://spring.io/guides/gs/serving-web-content/) to work and I'm trying to stick with the spring boot piece used in the example rather than bailing and creating my own servlet class, etc. Using Netbeans 8 on OS X Yosemite.

I've been able to resolve a number of issues along the course of this effort but now I'm stuck on this error. Let me know if more stack would be useful, my pom is below the error. Any direction is much appreciated:

---Stack trace---

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jacksonObjectMapperBuilder' defined in class path resource [org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.http.converter.json.Jackson2ObjectMapperBuilder]: Factory method 'jacksonObjectMapperBuilder' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.modulesToInstall([Lcom/fasterxml/jackson/databind/Module;)Lorg/springframework/http/converter/json/Jackson2ObjectMapperBuilder;  at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)    at

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)

---End Stack Trace excerpt---

---My POM---

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>gs-serving-web-content</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.5.RELEASE</version>
    </parent>

    <dependencies>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.2.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.1.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!--version>1.3.0.BUILD-SNAPSHOT</version-->
    </dependency>

    </dependencies>

    <properties>
        <java.version>1.7</java.version>
        <org.springframework.version>4.0.5.RELEASE</org.springframework.version>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <thymeleaf.version>2.1.4.RELEASE</thymeleaf.version>
    </properties>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestone</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestone</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>

</project>
like image 728
kly411 Avatar asked Jan 07 '23 19:01

kly411


2 Answers

Judging from the pom you are mixing at least 3 different spring versions (4.2.0, 4.1.4 and 4.0.5 and probably 4.1.6 from spring boot).

To fix remove all the additional org.springframework dependencies, those are already pulled in through the spring-boot-starter-web dependency.

Your properties also influence a couple of things, remove all of them but the java.version property (and if you really need it leave the thymeleaf property).

These changes lead to a set of libraries that are tested together and will leave you with a single spring version.

If you want to change the spring version, add a property in your <properties> element named <spring.version> and specify the specific spring version you want to use.

<properties>
    <spring.version>4.1.7.RELEASE</spring.version>
</properties>
like image 96
M. Deinum Avatar answered Jan 10 '23 08:01

M. Deinum


Remove all folders under your ".m2" folder and run maven build again. I got the issue fixed after few hour of struggle. Seems like some jars are in conflict and its good to get the new ones. -Hemant

like image 31
Hemant Avatar answered Jan 10 '23 09:01

Hemant