Skip to content

Spring Boot NoSuchMethodError From Mixed Spring Jar Versions

NoSuchMethodError in a Spring Boot app almost always means two Spring versions on one classpath. Find the jar that actually loaded, the override that put it there, and let the BOM own every version again.

nosuchmethoderror dependency-management maven gradle spring-upgrade spring-jvm spring-boot spring-errors
Gopi Gorantala
Reading Progress

On This Page

This line, sitting in a pom.xml since someone patched a CVE two years ago, is the most common cause of a NoSuchMethodError in a Spring Boot app that I know of:

<properties>
    <spring-framework.version>6.1.14</spring-framework.version>
</properties>

Nobody remembers adding it. Then the team bumps the Boot parent, everything compiles, the tests that ran go green, and the app dies at startup or on the first request with a method that "does not exist" in a Spring class. It does exist. It's in a different jar from the one the JVM picked.

The method that isn't there

When Spring Boot's failure analyzer recognises it, you get the banner instead of a raw trace. This block is assembled from the strings in Boot's NoSuchMethodFailureAnalyzer source on the current main branch, with the class names replaced by placeholders, so it's the shape and not a paste:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    <caller class>.<caller method>(<caller class>.java:<line>)

The following method did not exist:

    '<return type> <called class>.<method>(<parameter types>)'

The calling method's class was loaded from the following location:

    jar:file:/app/app.jar!/BOOT-INF/lib/<caller jar>.jar!/

The called method's class, <called class>, is available from the following locations:

    jar:file:/app/app.jar!/BOOT-INF/lib/<called jar>.jar!/<called class path>.class

The called method's class hierarchy was loaded from the following locations:

    <called class>: jar:file:/app/app.jar!/BOOT-INF/lib/<called jar>.jar!/

Action:

Correct the classpath of your application so that it contains compatible versions of the classes <caller class> and <called class>

When caller and callee are the same class, the Action line reads Correct the classpath of your application so that it contains a single, compatible version of <class> instead. Boot 2.4 printed a shorter version of the same report ("The method's class, … is available from the following locations"). If the error happens after startup, there's no analyzer and you get the plain JVM message. On Java 21 it looks like this (my lab output, further down):

Exception in thread "main" java.lang.NoSuchMethodError: 'java.lang.String com.example.ledger.core.Money.format(long, java.lang.String)'
    at com.example.ledger.web.SettlementView.render(SettlementView.java:4)

Java 8 prints the JVM descriptor form instead, which is how the most-searched Spring variant looks in old forum posts:

java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.isCandidateClass(Ljava/lang/Class;Ljava/lang/Class;)Z

That one is a classic. isCandidateClass is @since 5.2 in the AnnotationUtils javadoc, so seeing it means something compiled for Framework 5.2 (Boot 2.2) met a 5.1 jar at runtime.

Is it your code, or two Spring versions?

Look at the package of the missing method and the package of the caller. If both are org.springframework.* (or Hibernate, Jackson, Micrometer, anything Boot manages), you're almost certainly looking at two releases of one family on one classpath. If the caller is your own class, the usual story is a stale build: the class was compiled against a newer API than the jar you're running with.

Two minutes of checks, none of which need the app running:

./mvnw -q dependency:tree -Dincludes=org.springframework        # every Spring artifact and the version Maven chose
./mvnw help:effective-pom | grep -n 'spring-framework.version'     # who set the version property, and to what
./gradlew dependencyInsight --dependency spring-core --configuration runtimeClasspath
jar tf target/app.jar | grep 'BOOT-INF/lib/spring-'                  # what actually shipped in the fat jar

The last one is the one I trust most. spring-core-6.2.x.jar next to spring-webmvc-6.1.x.jar in BOOT-INF/lib is the whole diagnosis. All the Spring Framework modules are released together, and a Boot version is built and tested against exactly one Framework version.

My first instinct, every time I've hit this, was the IDE. Invalidate caches, mvn clean install -U, try again. It felt reasonable because the code compiles, and "compiles but fails at runtime" smells like stale state. It's not stale state. The build is resolving the versions you told it to, deterministically, every time. Clearing caches only re-downloads the same wrong jar.

Mix two versions on purpose

I couldn't pull Spring jars from Maven Central inside this session's workspace, so the lab uses two tiny libraries that behave exactly like two Framework modules: a ledger-core that gained a method in 1.1, and a ledger-web 1.1 that calls it. Gradle resolves them from a local folder, which means it runs offline and you can repeat it anywhere. The mechanism is the same one that breaks spring-webmvc against an older spring-core.

What you need: JDK 17+ and Gradle 8 (I ran OpenJDK 21.0.13 and Gradle 8.14.3).

1. Two versions of the core library. 1.0 has format(long). 1.1 adds an overload:

package com.example.ledger.core;

public final class Money {
    public static String format(long cents) { return format(cents, "EUR"); }
    public static String format(long cents, String currency) { // added in 1.1
        return String.format("%d.%02d %s", cents / 100, cents % 100, currency);
    }
}

2. The "web" library, compiled against core 1.1 and with a POM that declares ledger-core:1.1:

package com.example.ledger.web;

import com.example.ledger.core.Money;

public final class SettlementView {
    public String render(long cents) { return "settled " + Money.format(cents, "EUR"); }
}

Compile each with javac --release 17, jar them, and drop them into a Maven-layout folder (repo/com/example/ledger-core/1.0/ledger-core-1.0.jar plus a minimal .pom, and so on).

3. A merchant-settlement app that pins the core version, the way a leftover spring-framework.version property does:

plugins { id 'application' }
repositories { maven { url = uri("${rootDir}/../repo") } }

ext['ledger.version'] = '1.0'   // the "harmless" override
dependencies {
    implementation 'com.example:ledger-web:1.1'
    constraints {
        implementation("com.example:ledger-core") { version { strictly project.ext['ledger.version'] } } // forces the old core
    }
}
application { mainClass = 'com.example.settlement.SettlementJob' }
package com.example.settlement;

import com.example.ledger.core.Money;
import com.example.ledger.web.SettlementView;

public class SettlementJob {
    public static void main(String[] args) {
        System.out.println("Money loaded from: " + Money.class.getProtectionDomain().getCodeSource().getLocation());
        System.out.println(new SettlementView().render(1_234_56));
    }
}

4. Run it.

$ gradle --offline -q run
Money loaded from: file:/…/lab/repo/com/example/ledger-core/1.0/ledger-core-1.0.jar
Exception in thread "main" java.lang.NoSuchMethodError: 'java.lang.String com.example.ledger.core.Money.format(long, java.lang.String)'
    at com.example.ledger.web.SettlementView.render(SettlementView.java:4)
    at com.example.settlement.SettlementJob.main(SettlementJob.java:7)

Notice what didn't fail: compileJava. The app never calls the two-argument method itself, so javac had nothing to complain about.

5. Ask the build what it did.

$ gradle --offline -q dependencies --configuration runtimeClasspath
runtimeClasspath - Runtime classpath of source set 'main'.
+--- com.example:ledger-web:1.1
|    \--- com.example:ledger-core:1.1 -> 1.0
\--- com.example:ledger-core:{strictly 1.0} -> 1.0 (c)

1.1 -> 1.0 is the line to hunt for in your own tree. The library asked for one version and got another. dependencyInsight adds "Selection reasons: By constraint", which in a real project points straight at the override.

Confirmation signal: a NoSuchMethodError whose missing method exists in the newer jar (javap -cp ledger-core-1.1.jar com.example.ledger.core.Money lists it; the 1.0 jar doesn't). If you get NoClassDefFoundError instead, a whole class is missing, which usually means the versions are a major apart. That's a different article. And if the message mentions class file version, it's the JDK, not the jars: see Spring Boot 3 requires Java 17.

Teardown: delete the lab folder. Nothing was installed into ~/.m2 or ~/.gradle beyond Gradle's own cache.

What's going on, roughly

Your build resolved one Spring module to an older version than its siblings. Code in the newer module calls a method that was added in the newer sibling, the JVM looks it up in the older jar it actually loaded, and it isn't there.

Why javac was happy and the JVM wasn't

Java links method calls late. When ledger-web was compiled, javac wrote a symbolic reference into the class file: class Money, name format, descriptor (JLjava/lang/String;)Ljava/lang/String;. You can see it with javap -c:

3: invokestatic  #9   // Method com/example/ledger/core/Money.format:(JLjava/lang/String;)Ljava/lang/String;

Nothing checks that reference again until the JVM executes that instruction for the first time. Then it resolves Money through the class loader, gets whichever Money.class came first on the classpath, searches it for that exact name and descriptor, and throws NoSuchMethodError when the search fails. The descriptor includes the return type, so a method whose return type changed between versions breaks in exactly the same way even though "the method is right there" in the source.

Two consequences matter for Spring apps. The failure is lazy, so it only fires when the code path runs: startup if it's in auto-configuration, the first request if it's in a controller advice, 3 a.m. if it's in a batch job's error branch. And the class loader takes the first match. I proved that one with both core jars on the path:

$ java -cp classes:ledger-web-1.1.jar:ledger-core-1.0.jar:ledger-core-1.1.jar com.example.settlement.SettlementJob
Money loaded from: file:repo/com/example/ledger-core/1.0/ledger-core-1.0.jar
Exception in thread "main" java.lang.NoSuchMethodError: 'java.lang.String com.example.ledger.core.Money.format(long, java.lang.String)'

$ java -cp classes:ledger-web-1.1.jar:ledger-core-1.1.jar:ledger-core-1.0.jar com.example.settlement.SettlementJob
Money loaded from: file:repo/com/example/ledger-core/1.1/ledger-core-1.1.jar
settled 1234.56 EUR

Same jars, different order, different outcome. That's why "it works on my machine" is common with this error: an IDE classpath, a WEB-INF/lib and a Boot fat jar don't promise the same order.

The surprise for me, reading Boot's analyzer, was how much work it does that I'd been doing by hand. It finds every location the called class is available from and the location of each type in its hierarchy, which is precisely the "who loaded this" question. When you see two locations listed for one class, you're done diagnosing.

How the versions got mixed in a Boot build

Boot's spring-boot-dependencies BOM manages every Spring Framework module through one property, spring-framework.version (the names are in the dependency versions appendix). Mixing happens when something gets between that BOM and one module:

  • A stale property override. Set while patching a CVE on the old Boot line, never removed, and now older than what the new Boot needs.
  • Another BOM imported first. With Maven, when two imported BOMs manage the same artifact, the first one declared in dependencyManagement wins. A real case is spring-boot#25049: Boot 2.4.2 needed a method added in Framework 5.3.3, the classpath had spring-webmvc-5.3.2.jar, and the reply pointed at a Sleuth BOM imported in dependencyManagement.
  • An explicit version on one Spring dependency. spring-webmvc declared with its own version tag pins that module and nothing else.
  • Gradle's native platform(). It treats BOM versions as recommendations, so a library that drags in a newer spring-core wins for that module while its siblings stay put. Boot's Gradle plugin docs also say the spring-boot-dependencies properties don't work with native BOM support.
  • Spring classes you didn't declare at all: a shaded library that bundles its own copy of org.springframework, or Spring jars in an external Tomcat's lib folder ahead of your WAR.

Fixing a Spring NoSuchMethodError without pinning more versions

Find the module that's out of line first. dependency:tree with -Dincludes=org.springframework (or dependencyInsight on Gradle) shows which artifact resolved to a different version, and the effective POM shows who set the property. In a running system, start the JVM with -Xlog:class+load=info (JDK 9+; -verbose:class on 8) and grep for the class in the error; each line names the jar it came from:

[0.033s][info][class,load] com.example.ledger.core.Money source: file:repo/com/example/ledger-core/1.0/ledger-core-1.0.jar

That flag is noisy, so use it on one instance or locally, not across a fleet.

Then the fix depends on how the versions got mixed.

A stale property override: delete it. Let the Boot version you chose pick the Framework version. If you really need a newer Framework patch for a CVE, raise the property to that patch and put a comment with the CVE and a removal date next to it:

 <properties>
-    <spring-framework.version>6.1.14</spring-framework.version>
 </properties>

A BOM ordering problem without the starter parent: when you need a different Framework version, import spring-framework-bom before spring-boot-dependencies, because the first import wins:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>${spring-framework.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring-boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

And move any third-party BOM (Sleuth back then, a vendor SDK BOM today) after Boot's unless you've checked what it manages.

An explicit version on one module: remove the version tag and let the BOM manage it.

Gradle with platform(): either use the dependency management plugin and override with ext['spring-framework.version'], or align the whole group with a resolution rule, which is the mechanism Boot's docs show for native BOMs:

configurations.all {
    resolutionStrategy.eachDependency {
        if (requested.group == "org.springframework") {
            useVersion(springFrameworkVersion) // one version for every Framework module, defined once in the build
        }
    }
}

enforcedPlatform works too, but it also forces every other version in the BOM on you. Know that before you reach for it.

In the lab, removing the constraint was the whole fix:

$ gradle --offline -q run
Money loaded from: file:/…/lab/repo/com/example/ledger-core/1.1/ledger-core-1.1.jar
settled 1234.56 EUR

What doesn't fix it: adding the newer jar as an explicit dependency (now you have two pinned modules and the next upgrade breaks a third), sprinkling exclusions until the error moves somewhere else, or mvn clean install -U. Exclusions are fine when a library ships a jar you don't want at all; they're the wrong tool for picking a version.

Spring Data, Security, Batch and friends

Same mechanism, different property. Boot manages spring-data-bom.version, spring-security.version and the rest of the portfolio as release trains. A NoSuchMethodError from org.springframework.data.* with an override on spring-data-bom.version, or a Security module pinned separately from its siblings, gets the same treatment: one version per family, owned by the BOM. Spring Cloud has its own release train and its own compatibility check, which gets an article of its own.

Let one BOM own every Spring version

The setup that avoids this whole class is boring on purpose. Use spring-boot-starter-parent or import spring-boot-dependencies, and declare Spring dependencies without versions. Keep version overrides in one properties block, each with a reason and an expiry. Import other BOMs after Boot's. In Gradle, pick one mechanism (the plugin or native platforms) and stay with it across modules.

And treat every override as debt. The CVE patch you pinned on Boot 3.2 is exactly the line that breaks you on 3.4. I now grep for .version> in the properties block before every Boot bump, and it's the single most useful thing in my upgrade checklist.

Upgrades that change the Framework major (Boot 2 to 3 is Framework 5 to 6; Boot 3 to 4 is 6 to 7) make mixing worse, because a leftover old jar then misses whole classes, not methods. The Boot 2 to 3 migration article maps those.

The build check that would have caught this

Make the build refuse to mix versions instead of finding out at runtime.

Maven: the enforcer plugin's dependencyConvergence rule fails the build when two paths resolve one artifact to different versions. It's strict and will flag third-party conflicts too, so expect a first pass of cleanup. Gradle: configurations.all { resolutionStrategy.failOnVersionConflict() } does the equivalent.

A cheaper check that catches the Spring case specifically runs against the artifact you ship:

jar tf target/app.jar | grep -oE 'BOOT-INF/lib/spring-(core|beans|context|web|webmvc|aop|tx|jdbc|orm|expression)-[0-9.]+' \
  | sed -E 's/.*-([0-9.]+)$/\1/' | sort -u | wc -l     # anything other than 1 should fail CI

Then a smoke test that starts the packaged jar with the production profile. NoSuchMethodError thrown from auto-configuration shows up there in seconds, and it's the only test that sees the real fat-jar classpath.

On versions: the readable message format ('java.lang.String … format(long, java.lang.String)') is what Java 21 printed in my lab; Java 8 uses the descriptor form shown earlier. Boot's NoSuchMethodFailureAnalyzer has existed since the 2.x line and grew the caller-location section later; the strings I quoted are from the current main branch. Re-check spring-framework.version and every other override on each Boot upgrade, because on Boot 4.x (Framework 7) a leftover 6.x pin will almost certainly break startup.

What I checked for this one: the analyzer's description and action strings in Boot's source, the Gradle docs on overriding managed versions, the javadoc @since for the isCandidateClass variant, the Boot 2.4.2 issue, and both class-loader orders in the lab. What I didn't run: a real Spring Boot build, because the workspace had no access to Maven Central.

What to remember

  • NoSuchMethodError between two Spring classes means two Spring versions on one classpath. Look at BOOT-INF/lib before you look at your code.
  • The cause is almost always an override: a version property, a BOM imported in the wrong order, or one module with its own version.
  • Delete the override. Don't add another pin to balance it.
  • javac can't catch this. A convergence rule or a single-version check on the packaged jar can.

Things people search after this one

What does "An attempt was made to call a method that does not exist" mean in Spring Boot?

It's the description from Boot's NoSuchMethodFailureAnalyzer, which wraps a java.lang.NoSuchMethodError at startup. Read the "is available from the following locations" list: two jars for one class, or a jar version older than its siblings, is the cause. The Action line tells you which classes need compatible versions.

Is it safe to override spring-framework.version in Spring Boot?

Only for a patch release on the same line Boot already uses, and only temporarily. Each Boot release is tested against one Framework version, and an override that outlives the Boot upgrade it was meant for is the classic source of mixed jars. Leave a comment with the reason and remove it on the next Boot bump.

Why does NoSuchMethodError happen at runtime when the code compiles?

The compiler checks your code against the jars on the compile classpath, while the JVM resolves each method call the first time it runs, against whatever jar loaded the class. A library compiled against a newer Spring module can call a method your older jar doesn't have, and nothing notices until that line executes.

How do I find which jar a Spring class was loaded from?

Start the JVM with -Xlog:class+load=info (Java 9+) or -verbose:class (Java 8) and search for the class name; each entry shows the source jar. Inside the app, SomeClass.class.getProtectionDomain().getCodeSource().getLocation() returns the same thing. For a stack trace you don't understand yet, start with reading it bottom-up, and for the startup banner itself, see what APPLICATION FAILED TO START is telling you.

nosuchmethoderrordependency-managementmavengradlespring-upgradespring-jvmspring-bootspring-errors

Staff engineer architecting Kafka and Flink platforms for banking, where a dropped event is a reconciliation break, not a retry. Through javahandbook.com, I share production-tested guidance on building reliable event-driven systems.

Comments