Spring Boot 2 AuthoritiesExtractor - java

I encountered a problem when I tried to migrate from Spring Boot 1.5.10 to 2.0.0.RELEASE.
I have implemented the AuthoritiesExtractor interface and it's working in version 1.5.10, but in version 2.0.0 I got this error
class AuthoritiesExtractor not found in path org.springframework.boot.autoconfigure.security.oauth2.resource
It really can't be found.

The AuthoritiesExtractor interface has been moved from the spring-boot-autoconfigure dependency to the following dependency:
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
For versions >=2.0.0m5 (2.0.1.RELEASE - 2.1.3.RELEASE)
Import it via:
import org.springframework.boot.autoconfigure.security.oauth2.resource.AuthoritiesExtractor;

Solved
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>

Related

ClassNotfoundException in Maven Spring framework [duplicate]

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")
...
}

resilience4j + spring boot 2 + EndpointAutoConfiguration class not found exception

Resilience4j version: 1.1.0
Java version: 1.8
Spring boot : 2.2.0
I am trying to configure the Resilience4j with spring boot project but getting below class not found
org.springframework.boot.SpringApplication: Application run failed
java.lang.IllegalArgumentException: Could not find class [org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration]
at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:327)
Java Code as follows :
#RateLimiter(name ="service1",fallbackMethod = "rateLimiterfallback")
#PostMapping(value = "${URL_AUTH}")
public ResponseEntity<AuthRespDTO> fetchToken(#RequestParam("userId") String Id, #RequestParam("password") String pwd, HttpServletRequest httpRequest) {
}
application.yml as below
resilience4j.ratelimiter:
instances:
service1:
limitForPeriod: 1
limitRefreshPeriod: 100000
timeoutDuration: 1000ms
I have below dependencies mentioned in POM.xml .
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot2</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-ratelimiter</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
Please help me in resolving the issue .
For fixing this issue you have to update the POM with the spring-boot-starter-actuator and spring-boot-starter-aop dependencies.
At present you have a dependency of spring-boot-actuator which should be updated to spring-boot-starter-actuator.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>2.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>
Note : Release version of spring boot depends on your project.
Similar issue reference

Unable to resolve #RestController annotation in spring 2.0.3

I am making a new springboot- maven project. The compiler is unable to resolve #RestController when I use below pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
However, when I change the version to 1.5.13, the compiler is able to resolve #RestController
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.13.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
I want to be using the latest version of spring boot, and use #RestController.
#RestController doesn't come from org.springframework.boot:spring-boot-starter-web, it comes from org.springframework:spring-web. Different versions of spring-boot-starter-web must probably have some transient dependency that provides it, but it's a bad practice to rely on it. If you use #RestController in your code, you should explicitly require the artifact that provides it:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
since i can't add a comment, i think the maven config is not your problem, check your #Configuration and #SpringBootApplication classes and their path scanning settings
another problem you could have: maybe one of your other dependencies still depends on springboot 1.5, you have to have a clean springboot 2.0 classpath
i run in problems like this as well, so keep on diggin, you'll find it ;-)
I had somewhat a similar issue and it was because I named my class RestController. Once I renamed it Controller, I could import the #RestController packages without issues.

Building maven spring boot project throws error

I am new to spring boot. I am trying to migrate project from old spring boot to the latest version.
I changed the version of spring boot in project. But when i build the project it fails in tests throwing computational failure with error below
package org.springframework.test.annotation does not exist
I have this dependency in my project
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
Not sure what i could be missing?
Change spring-boot-test TO spring-boot-starter-test like below :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
to
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
Refer http://www.baeldung.com/spring-boot-starters for more info about starters.

Cannot find org.springframework.integration.Message when using spring-boot-starter-integration

I'm using Spring boot and want to use the starter pom for Spring Integration.
In my POM I have:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
This pulls in 4.3.6 versions of Spring Integration jars and 4.3.5 of Spring Framework jars. In one of my own classes I'm trying to use Message:
import org.springframework.integration.Message;
public Object doThings(Message<?> message) {
}
but I can't seem to locate Message. In an older version of Spring integration it was in spring-integration-core.jar but it's not there in this version. Has it moved or has something changed? I've checked the docs and it's still referenced so I assume I'm looking in the wrong place - but core sounds like the place it should be in to me! What am I doing wrong?
A few core concepts of Spring Integration have been merged inside Spring Core between versions 3.0 and 4.0, and org.springframework.integration.Message is one of them.
In your code sample, replacing
import org.springframework.integration.Message;
public Object doThings(Message<?> message) {
}
by
import org.springframework.messaging.Message;
public Object doThings(Message<?> message) {
}
will do the trick.
For a more exhaustive list of affected classes and interfaces, have a look at the 3.0 to 4.0 Spring Integration migration guide
It ok for me with using this version
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
<version>4.1.9.RELEASE</version>
</dependency>
and
import org.springframework.messaging.Message;

Categories

Resources