Am very new to spring and JUnit. Am trying to run a simple JUnit test case for spring service class, but it fails and I get this exception.I didnt write any test yet, but t
The problem is that you are mixing different versions of Spring, you are mixing (2.0.8, 3.1.4 and 4.0.2) in your project. That is trouble waiting to happen.
To prevent these kind of things there is now a so called "bill of materials" POM which you can import.
You need to add a dependencyManagement section to import the bom.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.0.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Now in your dependencies you can remove the version and replace spring-dao
with spring-orm
. Added benefit is that all your spring-* dependencies will now be managed to the latest release and you only have a single location for your version number.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
You could apply the same trick for Spring Data as that also has a bom.
That method appeared in that commit, which seems to be 4.0.3+. Just update spring dependencies to the latest version.
Replace your old jars with new one's based on the spring-framework-bom.LATEST.VERSION.pom file.
That way, i had resolved my issue.
I just deleted the target folder in my maven project and rebuilt the war and this problem vanished.
Try this from https://stackoverflow.com/a/63215379/9225032:
Just check all spring dependencies versions. All should be same or at least new. Example:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>