Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Maven Dependency for latest and old version conflicts

Am using spring-data-dynamoDB project from here, as per its pom.xml they have used 1.6.9.1 version of aws-java-sdk, but I need to use latest version of aws-java-sdk for my project for using some of its features to implement Amazon s3 too. If I include its dependency,

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk</artifactId>
    <version>1.7.9</version>
</dependency>

am getting an exception as follows,

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]
.......
.......

I have tried exclusions as follows and also the same result,

<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>

Is it possible to use latest version of aws-java-sdk in my project now?? or else spring-data-dynamoDB pom.xml have to be updated if so only I am able to use it or what?? Thanks Michaellavelle for that tremendous project. It helps me alot for completing DynamoDB part.

like image 265
jAddict Avatar asked May 23 '14 07:05

jAddict


3 Answers

Thanks you @user944849. The problem is jackson libs used in aws-java-sdk which is lower version as of in spring-data-rest-webmvc and conflicts with it, so by excluding jackson libs from aws-java-sdk builds correct. Solution I got is,

<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>

I am unable to post an answer early because of reputation. This may be useful for others who stuck as like me. Thank you.

like image 194
jAddict Avatar answered Oct 07 '22 19:10

jAddict


For some reason excluding jackson from aws-java didn't work for me.

java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z

Looking at the issue, it looks like jackson is not available, or we have the wrong version floating around in the project. This method appears to have been added in 2.3.0, the latest version of jackson. I added a dependency to the latest version of jackson, and my code is now happy.

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-s3</artifactId>
    <version>1.9.6</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.3.0</version>
</dependency>

I'm not sure if annotation and databind are necessary. Also, I'm working on a huge project, so different forms of jackson might be coming in from various other dependencies, jersey, google-http-client-jackson2. So, it's also wise to look at the maven dependency graph to see where any jackson's are coming from.

like image 3
Peter Dietz Avatar answered Oct 07 '22 18:10

Peter Dietz


The error is NoClassDefFound for com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering. I searched for that class in GrepCode and discovered it is in the com.fasterxml.jackson.core:jackson-core library. My guess is that the two versions of the aws-java-sdk library you tried are specifying different jackson-core library versions as transitive dependencies. Your application may be explicitly depending on jackson-core as well - an older version than the one required by the later aws-java-sdk. The project needs to use a version of jackson-core that contains the requiresPropertyOrdering method. You should be able to see all of the transitive dependencies by running mvn dependency:tree (or the equivalent in your IDE).

One fix is to add the jackson-core library to a <dependencyManagement> block in the project's POM (or the parent POM) to make sure the right version gets used.

like image 2
user944849 Avatar answered Oct 07 '22 17:10

user944849