Reputation: 211
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>
Upvotes: 18
Views: 71428
Reputation: 2424
As Manuel Jordan suggested, it is because of the difference in versions. I just got this error and solved it by setting the same version of org.springframework:spring-core in each one of my modules.
My project structure is as follows:
projectname
module1
module2
module3
I wrote a test under module2:
projectname
module1
module2
src
test
< my package >/TestClass.java
module3
When I ran this test, I got this error:
java.lang.NoClassDefFoundError: org/springframework/core/ErrorCoded
After ensuring each module had the same version of the org.springframework:spring-core dependency, the test ran.
Upvotes: 2
Reputation: 115
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
Upvotes: 5
Reputation: 16301
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
Upvotes: 22
Reputation: 1748
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>
Upvotes: 4