I am currently playing with some proof-of-concept work in Spring Boot and GCP data storage.
My pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-data-datastore</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
Issue: Spring Boot fails to start
When I attempt to launch the application, I get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:251)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:264)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
What I tried
I tried adding the Actuator dependency.
But that did not do the trick.
I cannot figure out what dependency I am missing. I see the class definition here in 5.3.0-M2 documentation, but I'm not sure what dependency it exists in.
I also tried adding following metrics dependencies:
spring-cloud-gcp-starter-metrics
spring-metrics
spring-cloud-stream-metrics
I searched in findjar.com with no luck.
I wouldn't mind disabling it as well if that is possible.
Update:
I added:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.1</version>
</dependency>
Which gives me a new error:
An attempt was made to call a method that does not exist. The attempt
was made from the following location:
org.springframework.boot.SpringApplication.run(SpringApplication.java:324)
The following method did not exist:
'void org.springframework.context.ConfigurableApplicationContext.setApplicationStartup(org.springframework.core.metrics.ApplicationStartup)'
The method's class,
org.springframework.context.ConfigurableApplicationContext, is
available from the following locations:
...
Action:
Correct the classpath of your application so that it contains a
single, compatible version of
org.springframework.context.ConfigurableApplicationContext
I was able to solve this by downgrading Spring Boot:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
Guess it's just not compatible with 2.4.0 yet.
Specifically I also had to ensure that I used 2.3.3.RELEASE and not anything more recent due to other issues I ran across.
I don't have the spring-cloud dependency, but when upgrading to Spring Boot 2.4 from 2.3 I got the same error.
Exception in thread "main" java.lang.NoClassDefFoundError:
org/springframework/core/metrics/ApplicationStartup
Per conversation in this thread (https://github.com/spring-projects/spring-boot/issues/24880) I upgraded to Spring Framework 5.3.3 and it fixed the problem.
I had the same issue caused by an old version of spring-context JAR file loaded instead of the appropriate version.
Ensure that there were no reminiscence of old libraries in your classpath.
I had a similar issue, and it was resolved by adding the following maven dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.3.8</version>
</dependency>
I was having the same issue but with:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.9.RELEASE</version>
<scope>test</scope>
</dependency>
And the error disappeared after I upgraded to:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.3</version>
<scope>test</scope>
</dependency>
May this help, upgrade spring-cloud to the latest version.
This works for me when I faced your first error :
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
See the twitter thread here, thanks to Stéphane and Arnaud for the help.
I had the same problem, but that was caused by spring-security-ldap that i also import in version 5.4.x
Upgrade spring-security-ldap to version 5.5.0 solved the problem for me.
I had this issue when adding a Spring Boot test to a library for the first time. In my case, the library did not have a Spring Boot application.
This did the trick:
#SpringBootApplication
public class TestApplication {
public static void main(final String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
Using only spring-boot-starter-test as a Spring dependency.
Check if another dependency doesn't have dependency to spring-core with older version
May this will help someone, who is facing this error.
=> Error should look like this:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:229)
at org.springframework.context.support.GenericApplicationContext.<init>(GenericApplicationContext.java:112)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:67)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:91)
Solution to the Problem:-
Go to Project folder\ Right click\ Maven\ Update maven project.
Check your Spring version (pom.xml-> view the properties).
Change the Spring version to an older/new version..Otherwise use this
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<spring.version>5.2.0.RELEASE</spring.version> <!--add this version-->
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<dependency>
<groupId>org.springframework</groupId> <!-- sql dependency for jdbc-->
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
After adding above things, Save it(Please wait for the code to build..).
Run your Program
All The Best Guys, Let's Move Togther
I had the same Spring Boot ClassNotFoundException ApplicationStartup issue, the solution was for me to ensure that the spring boot version in my gradle plugin is the same than the dependencies in my build.gradle.kts like:
plugins {
id("org.springframework.boot") version "2.5.3"
...
}
dependencies {
implementation("org.springframework.boot:spring-boot:2.5.3")
...
}
I am using Maven to set up dependency in my app.
I am using Spring Boot v2.1.12.RELEASE which brings in Spring Core v5.1.13.
But there also a library Spring Integration v5.1.9 (which is latest) and brings Spring Core v5.1.11.RELEASE
As you can see that I want Spring Integration to not resolve to v5.1.11 of Spring Core as it has some vulnerabilities.
Is there any way to specify in POM for Spring Integration to resolve to 5.1.13 of Spring Core (instead of 5.1.11) ?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.12.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>5.1.9</version>
</dependency>
P.S I do not want to upgrade to the latest release of Spring Boot.
Use maven exclusion tag to exclude the transitive dependency, make sure the excluded library is directly added to pom or it's pulled in by some other dependency.
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>5.1.9</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.11.RELEASE</version>
</exclusion>
</exclusions>
</dependency>
DISCLAIMER: This is just a work around solution for your immediate need, use it only when no other options are possible as managing spring managed dependencies ourself is not maintainable in long run.
I used the recommendation in the post Dependency Management to overcome my challenge.
So I excluded the spring-core dependency from spring integration and also added the spring core library using below code
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.13.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
I am having problem "EnableTransactionManagement cannot be resolved to a type" though I have spring-tx jar already in my project. Can someone please suggest me what I am doing wrong. I am using Hibernate 4, Eclipse, Spring version 4.3.2. I am posting snapshot of my problem.
Thankyou!
You need to add spring-orm dependency into your pom.xml file.
<!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
According to the springio documentation here I should be able to just cut and paste this...
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework</artifactId>
<version>4.0.5.RELEASE</version>
</dependency>
</dependencies>
...into my maven pom, which I did, but it fails to resolve the version.
So I looked and found this and I added a proxy repository to my nexus for the [release] (http://repo.spring.io/release) repository but still failed to locate the artifact.
Then I navigated to the http://repo.spring.io/release repo and manually searched and CANNOT FIND the artifact.
So, where I am going wrong?
That's a mistake in the guide.
Somewhere below it mentions "spring-context", so I believe that should have been:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.5.RELEASE</version>
</dependency>
Notice "spring-context" instead of "spring-framework".
Github issue to have that fixed: Github issue.
I have a Maven/Java project using Spring 3.2.5.RELEASE, which uses component scanning to pick up an #Controller with a number of #RequestMapping annotations and set up the appropriate endpoints.
As soon as I bring in a dependency on spring-data-jpa 1.4.1.RELEASE, the mappings stop being wired up (although the server still starts up without any errors).
The problem is that when you add spring-data-jpa 1.4.1.RELEASE to the pom.xml, it download spring-orm-3.1.4 and others 3.1.4 dependencies. Those Dependencies are incompatible with 3.2.5 so you need do download manually.
To solve the problem you need to say maven to use the correct dependencies. ie. put in the pom.xml the next dependencies:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>