Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Solving Spring NoClassDefFoundError, ClassNotFoundException, and MethodNotFoundExceptions Errors

DZone's Guide to

Solving Spring NoClassDefFoundError, ClassNotFoundException, and MethodNotFoundExceptions Errors

We take a look at some common Spring Boot questions when it comes to some popular exceptions. Read on to find out how to deal with them.

· Java Zone
Free Resource

Learn how our document data model can map directly to how you program your app, and native database features like secondary indexes, geospatial and text search give you full access to your data. Brought to you in partnership with MongoDB.

I see a lot of Spring questions on StackOverflow about NoClassDefFoundError, ClassNotFoundException, and MethodNotFoundExceptions, especially with Spring Boot. The cause is nearly always a change to a build dependency in Gradle or Maven that has resulted in the mixing of dependencies. This post considers how approach these issues, providing a starting point, and possibly resolving these issues.

  • Do a clean build – the conflict is being caused by out of date libraries in the maven repository
  • If problems still exist then check Spring’s bill-of-materials to see what versions are recommended, and if they are in conflict with your own pom file versions. The purpose of the bom is discussed in my previous post(https://glenware.wordpress.com/2016/09/07/maven-bill-of-materialsbom/)
  • Check which spring-framework-bom you are using – the import will be of the form:
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>4.3.2.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

In this case we are using 4.3.2.RELEASE. You can then check what versions of other packages spring is using using mvnrepository (https://mvnrepository.com/artifact/org.springframework/spring-framework-bom/4.3.2.RELEASE).

If the above highlights a conflict then your options are:

  • Use the Spring Dependencies – Can you use the dependency version from the spring-bom or dependencies?
  • Dependency Management – can you manage the issue through dependency management?
  • Code Change – It may be that you are upgrading your spring boot or spring version to the latest version. It might be the API’s have changed, so you have to change your code. Time to get the manuals out.

Discover when your data grows or your application performance demands increase, MongoDB Atlas allows you to scale out your deployment with an automated sharding process that ensures zero application downtime. Brought to you in partnership with MongoDB.

Topics:
build ,dependency ,maven ,questions ,spring boot ,issues ,dependencies ,spring ,java ,exceptions

Published at DZone with permission of Martin Farrell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}