java Spring web mvc 示例,启动,创建名为“jacksonObjectMapperBuilder”的 bean 时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31941803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring web mvc example, boot, Error creating bean with name 'HymansonObjectMapperBuilder'
提问by kly411
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.
我是 Spring 的新手,主要是 Java 语言本身之外的......最小的控制台应用程序等。我试图在此处获取 Spring 网站示例(https://spring.io/guides/gs/serving-web -content/) 工作,我试图坚持使用示例中使用的弹簧引导件,而不是放弃和创建我自己的 servlet 类等。在 OS X Yosemite 上使用 Netbeans 8。
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:
在这项工作的过程中,我已经能够解决许多问题,但现在我陷入了这个错误。让我知道更多堆栈是否有用,我的 pom 低于错误。任何方向都非常感谢:
---Stack trace---
- -堆栈跟踪 - -
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'HymansonObjectMapperBuilder' defined in class path resource [org/springframework/boot/autoconfigure/Hymanson/HymansonAutoConfiguration$HymansonObjectMapperBuilderConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.http.converter.json.Hymanson2ObjectMapperBuilder]: Factory method 'HymansonObjectMapperBuilder' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.http.converter.json.Hymanson2ObjectMapperBuilder.modulesToInstall([Lcom/fasterxml/Hymanson/databind/Module;)Lorg/springframework/http/converter/json/Hymanson2ObjectMapperBuilder; 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---
---我的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>
回答by M. Deinum
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).
从 pom 来看,您正在混合至少 3 个不同的 spring 版本(4.2.0、4.1.4 和 4.0.5 以及可能来自 spring boot 的 4.1.6)。
To fix remove all the additional org.springframework
dependencies, those are already pulled in through the spring-boot-starter-web
dependency.
要修复删除所有附加org.springframework
依赖项,这些依赖项已经通过spring-boot-starter-web
依赖项引入。
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).
您的属性也会影响一些事情,移除所有java.version
属性,但属性除外(如果您真的需要它,请保留 thymeleaf 属性)。
These changes lead to a set of libraries that are tested together and will leave you with a single spring version.
这些更改导致了一组一起测试的库,并将为您提供一个 spring 版本。
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.
如果要更改 spring 版本,请在<properties>
名为的元素中添加一个属性<spring.version>
并指定要使用的特定 spring 版本。
<properties>
<spring.version>4.1.7.RELEASE</spring.version>
</properties>
回答by Hemant
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
删除“.m2”文件夹下的所有文件夹并再次运行 maven build。经过几个小时的斗争,我解决了这个问题。似乎有些罐子发生冲突,获得新罐子是件好事。-Hemant
回答by kly411
RESOLVED. Once I reverted to the original example pom and studied the original trace more closely I spotted my very simple oversight/issue which was missing templates directory.
解决。一旦我恢复到原始示例 pom 并更仔细地研究原始跟踪,我发现了我的非常简单的疏忽/问题,即缺少模板目录。
回答by Jens
The method is introduced in Version 4.1.5:
该方法在4.1.5版本中引入:
Read the documentation
阅读文档
modulesToInstall
public Hymanson2ObjectMapperBuilder modulesToInstall(Module... modules) Specify one or more modules to be registered with the ObjectMapper. Modules specified here will be registered after Spring's autodetection of JSR-310 and Joda-Time, or Hymanson's finding of modules (see findModulesViaServiceLoader), allowing to eventually override their configuration. Specify either this or modules, not both.
Since: 4.1.5 See Also: Module
要安装的模块
public Hymanson2ObjectMapperBuilder modulesToInstall(Module... modules) 指定一个或多个要注册到 ObjectMapper 的模块。此处指定的模块将在 Spring 自动检测 JSR-310 和 Joda-Time 或 Hymanson 发现模块后注册(请参阅 findModulesViaServiceLoader),从而最终覆盖其配置。指定 this 或 modules,而不是两者。
从:4.1.5 另见:模块
So try to change to this spring version.
所以尽量换到这个spring版本。