我是 Spring 的新手,除了语言本身之外,我主要是 Java ......最小的控制台应用程序等。我正在尝试让 Spring 网站示例(https://spring.io/guides/gs/serving-web-content/)工作,我正在努力坚持使用示例中使用的 spring boot 部分,而不是 bailing 和创建我自己的 servlet 类等。在 OS X Yosemite 上使用 Netbeans 8。
在这项工作的过程中,我已经能够解决许多问题,但现在我陷入了这个错误。让我知道更多堆栈是否有用,我的 pom 低于错误。非常感谢任何方向:
---堆栈跟踪---
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)
---结束堆栈跟踪摘录---
---我的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>
最佳答案
从 pom 来看,您至少混合了 3 个不同的 spring 版本(4.2.0、4.1.4 和 4.0.5,可能还有来自 spring boot 的 4.1.6)。
修复删除所有额外的 org.springframework
依赖项,那些已经通过 spring-boot-starter-web
引入了依赖。
您的属性也会影响一些事情,删除所有这些,但 java.version
属性(property)(如果你真的需要它离开 thymeleaf 属性(property))。
这些更改导致一组库被一起测试,并将留给您一个单一的 spring 版本。
如果要更改 spring 版本,请在 <properties>
中添加一个属性名为 <spring.version>
的元素并指定您要使用的特定 spring 版本。
<properties>
<spring.version>4.1.7.RELEASE</spring.version>
</properties>
关于java - Spring web mvc 示例,引导,创建名称为 'jacksonObjectMapperBuilder' 的 bean 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31941803/