Question

it appears that the GA versions of

spring-core
spring-data-commons
spring-data-mongodb

as well as the most recent release candidate of

spring-boot-starter-web
spring-boot-autoconfigure

are not compatible.

what versions of these artifacts are compatible with each other?

I have a very basic Application.java that puts two objects into a MongoDB database and then takes them out and prints them to the screen.

import game.acorn.entities.Entity;
import game.acorn.mRepositoryInterfaces.EntityRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application implements CommandLineRunner{

    @Autowired
    private EntityRepository repository;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    public void run(String... args) throws Exception {

        repository.deleteAll();

        repository.save(new Entity("Jack", "Skellington"));
        repository.save(new Entity("Blake", "Yarbrough"));

        System.out.println("Entities found");
        for (Entity entity : repository.findAll()){
            System.out.println(entity);
        }

        System.out.println();
        System.out.println("Entity by first name 'Jack'");
        System.out.println(repository.findByFirstName("Jack"));

        System.out.println();
        System.out.println("Entity by first name 'Blake'");
        System.out.println(repository.findByFirstName("Blake"));
    }


}

When I run this application with

spring-core               version 4.0.2.RELEASE
spring-data-commons       version 1.5.0.RELEASE
spring-boot-starter-web   version 1.0.0.RC4
spring-data-mongodb       version 1.4.1.RELEASE
spring-boot-autoconfigure version 1.0.0.RC3

I end up getting a java.lang.NoClassDefFoundError at

org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.registerBeanDefinitions

which looks like

public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
        final BeanDefinitionRegistry registry) {
    new RepositoryConfigurationDelegate(getConfigurationSource(), this.resourceLoader)
            .registerRepositoriesIn(registry, getRepositoryConfigurationExtension());
}

with

new RepositoryConfigurationDelegate(getConfigurationSource(), this.resourceLoader)

being the line 58. It seems that there is a discrepancy between the version I am using and spring-boot's dependency.

So I try to up version my spring-data-commons to version 1.7.0.RELEASE

and then the class becomes available but I then get a java.lang.NoSuchMethodError at

org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport$1.<init>(AbstractRepositoryConfigurationSourceSupport.java:66)

which looks like

private AnnotationRepositoryConfigurationSource getConfigurationSource() {
        StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(
                getConfiguration(), true);
        return new AnnotationRepositoryConfigurationSource(metadata, getAnnotation(),
                this.environment) {
            @Override
            public java.lang.Iterable<String> getBasePackages() {
                return AbstractRepositoryConfigurationSourceSupport.this
                        .getBasePackages();
            };
        };
    }

with

return new AnnotationRepositoryConfigurationSource(metadata, getAnnotation(),
            this.environment) {

being lines 65-66.

when I check out

org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource

I find that the constructor

public AnnotationRepositoryConfigurationSource(AnnotationMetadata metadata, Class<? extends Annotation> annotation,
            ResourceLoader resourceLoader, Environment environment) {

        super(environment);

        Assert.notNull(metadata);
        Assert.notNull(annotation);
        Assert.notNull(resourceLoader);

        this.attributes = new AnnotationAttributes(metadata.getAnnotationAttributes(annotation.getName()));
        this.metadata = metadata;
        this.resourceLoader = resourceLoader;
    }

expects one more argument than AbstractRepositoryConfigurationSourceSupport in spring-boot-autoconfigure gives it.

So, my question is, what versions of

spring-core
spring-data-commons
spring-boot-starter-web
spring-data-mongodb
spring-boot-autoconfigure

are compatible with each other?

my pom looks like

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

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.0.0.RC3</version>
    </parent>
  <groupId>Master-Project</groupId>
  <artifactId>Master-Project</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <description>Master Project for MongoDB and Spring</description>

  <modules>
  </modules>

  <dependencies>

    <!-- Spring Stuff -->  

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.0.2.RELEASE</version>
    </dependency>  
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-mongodb</artifactId>
        <version>1.4.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
        <version>1.7.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>1.0.0.RC3</version>
    </dependency>



    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
    </dependency>   

    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>3.1</version>      
    </dependency>

  </dependencies>
  <repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>http://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
    <!--
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.3</source>
          <target>1.1</target>
        </configuration>
      </plugin>
    -->
      <plugin>
        <groupId>org.apache.maven.plugin</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.9</version>
        <configuration>
            <downloadSources>true</downloadSources>
            <downloadJavadocs>true</downloadJavadocs>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

When I remove the version tags on the dependencies I get the same no such method exception.

Was it helpful?

Solution

This is fixed if you use the Spring Boot dependencies pom (or the starter parent) with 1.0.0.RC5 or better.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top