Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: org/springframework/core/DefaultParameterNameDiscoverer

I am trying to work out my spring hibernate with maven dependencies.

My server is not starting up and throwing this error:

java.lang.NoClassDefFoundError: org/springframework/core/DefaultParameterNameDiscoverer

I don't know whether it is a problem with my dependencies or with my server. Let me know if anything would be needed from my project. Here are the dependencies I've added in my pom.xml file. I am using maven 4.0.0.

<properties>
    <spring.version>3.0.5.RELEASE</spring.version>
</properties>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

    <!-- Spring 3 dependencies -->
    <dependency> 
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId> 
        <version>${spring.version}</version> 
    </dependency> 

    <!-- <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.2.3.RELEASE</version>
    </dependency>  -->

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.0.6.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.5.Final</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

    <!-- Hibernate annotation -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>4.3.5.Final</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.31</version>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>abc</id>
        <url>http://repo1.maven.org/maven2</url>
    </repository>
</repositories>
like image 948
Kumar M Avatar asked Jul 10 '14 21:07

Kumar M


3 Answers

Is not wise mix Spring versions in one project.

The error is, you have the spring-core module working with 3.0.5 and the rest of modules with 4.0.6

like image 160
Manuel Jordan Avatar answered Nov 16 '22 12:11

Manuel Jordan


Already posted ansewers are correct. This issue is caused by conflicts in dependency version. The fastest way in my opinion to resolve those confilcts is to use plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.4.1</version>
    <configuration>
        <rules><dependencyConvergence/></rules>
    </configuration>
</plugin>

Run it with mvn enforcer:enforce command. You will get a list of conficted dependencies. Check the library that has the lowest version of certain dependency and downgrade others. It is slow precess though so be patient

like image 5
sylikon Avatar answered Nov 16 '22 13:11

sylikon


Resolution to this problem would depend on your pom.xml and what spring library it has. Some rejig of the spring jars including and excluding spring jars in maven will resolve this.

I added the following to resolve the mongo-db spring-data jar related issue.

<properties>
        <spring.version>3.2.4.RELEASE</spring.version>
        <spring.data.version>1.6.1.RELEASE</spring.data.version>
        <spring.core.version>4.1.4.RELEASE</spring.core.version>
    </properties>

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-beans</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-aop</artifactId>
                </exclusion>
            </exclusions>   
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.core.version}</version>                           
        </dependency>

            <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>4.1.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>${mongo.driver.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jongo</groupId>
            <artifactId>jongo</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
            <version>${spring.data.version}</version>
        </dependency>
like image 4
Smart Coder Avatar answered Nov 16 '22 11:11

Smart Coder