使用来自here的spring-data-dynamoDB项目,根据其pom.xml,他们使用 1.6.9.1 版本的 aws-java-sdk < / strong>,但我需要在我的项目中使用最新版本的aws-java-sdk,以便使用它的一些功能来实现Amazon s3。如果我包含其依赖项,
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.7.9</version>
</dependency>
我得到如下例外,
12:51:25.298 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)': [_relProvider]
12:51:25.307 [main] ERROR o.s.w.c.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.hateoas.config.HypermediaSupportBeanDefinitionRegistrar$Jackson2ModuleRegisteringBeanPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_halObjectMapper': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.fasterxml.jackson.databind.ObjectMapper]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
.......
.......
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_halObjectMapper': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.fasterxml.jackson.databind.ObjectMapper]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1076) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
.......
.......
我已尝试排除如下,同样的结果,
<dependency>
<groupId>org.socialsignin</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>1.0.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
</exclusion>
</exclusions>
</dependency>
现在可以在我的项目中使用最新版本的aws-java-sdk吗?或者必须更新spring-data-dynamoDB pom.xml,如果是这样,我只能使用它或者什么? 感谢Michaellavelle这个伟大的项目。它有助于我完成DynamoDB部分。
答案 0 :(得分:19)
谢谢你@ user944849。问题是在aws-java-sdk中使用的jackson libs是spring-data-rest-webmvc中的较低版本并与之冲突,所以通过从aws-java-sdk构建正确的jackson libs排除。我得到的解决方案是,
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.7.9</version>
<exclusions>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-annotations</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
由于声誉,我无法提前回复。对于像我一样坚持的人来说,这可能会有用。谢谢。
答案 1 :(得分:2)
错误为NoClassDefFound for com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering
。我在GrepCode中搜索了该类,并发现它位于com.fasterxml.jackson.core:jackson-core
库中。我的猜测是你尝试的aws-java-sdk
库的两个版本将不同的jackson-core库版本指定为传递依赖。您的应用程序可能也明确取决于jackson-core
- 旧版本的版本低于后者aws-java-sdk
所需的版本。该项目需要使用包含requiresPropertyOrdering方法的jackson-core版本。您应该能够通过运行mvn dependency:tree
(或IDE中的等效项)来查看所有传递依赖项。
一个解决方法是将jackson-core
库添加到项目的POM(或父POM)中的<dependencyManagement>
块,以确保使用正确的版本。