Ask questionsMigrating OAuth2 from Spring Boot 1.5 to 2.0 Broken

I am migrating from Spring Boot 1.5 to 2.0. When providing a success handler to HttpSecurity, a ClassNotFoundException is thrown for Here's a simple way to reproduce:

public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    public void configure(HttpSecurity http) throws Exception {
                .antMatchers("/", "/login**", "/")
                .authenticated().and().oauth2Login().successHandler(new SecurityHandler());

and SecurityHandler:

public class SecurityHandler implements AuthenticationSuccessHandler {
    public void onAuthenticationSuccess(HttpServletRequest var1, HttpServletResponse var2, Authentication var3) throws IOException, ServletException {

Everything works fine until you add the successHandler. At that point, Spring fails to boot due to the class not found:

Caused by: java.lang.ClassNotFoundException:
	at ~[na:1.8.0_121]
	at java.lang.ClassLoader.loadClass( ~[na:1.8.0_121]
	at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass( ~[patriotic-web.jar:0.0.1-SNAPSHOT]
	at java.lang.ClassLoader.loadClass( ~[na:1.8.0_121]
	... 56 common frames omitted

Answer questions konstantin-doncov

@philwebb hi! I faced the same problem. OAuth2 worked fine, but when I added(from this answer):

 http.oauth2Login().failureHandler(new CustomAuthenticationFailureHandler());

then I got ClassNotFoundException. After that I added spring-security-oauth2-client and got

Bean method 'clientRegistrationRepository' not loaded because OAuth2 Clients Configured Condition registered clients is not available

Do I need to add these properties, if I already have oauth_client_details table with my clients in my DB and all worked fine until failureHandler()?


Related questions

Upload file org.springframework.web.multipart.MultipartException - spring-boot hot 6
Dependency resolution fails with Gradle 5.3.x to 5.6.x
Controller annotated with @Timed and active TimedAspect clashes with WebMvcMetricsFilter hot 4
[spring-boot 2.3.0] ResponseStatusException reason is ignored - spring-boot hot 3
No bean named 'entityManagerFactory' available hot 3
Caused by: java.lang.IllegalArgumentException: class is not assignable to interface org.springframework.context.ApplicationListener - spring-boot hot 3
get error messag Could not fetch the SequenceInformation from the database, hibernate_sequence doesn't exist hot 2
Source file must be provided failure when running spring-boot:repackage from the command-line hot 2
Actuator: NPE in LongTaskTimingHandlerInterceptor hot 2
ConfigurationProperties with constructor binding cannot be mocked hot 2
NoClassDefFoundError: net/bytebuddy/NamingStrategy$SuffixingRandom$BaseNameResolver hot 2
SNAPSHOT Dependency with Spring Boot Starter Parent POM 2.3.1.RELEASE - spring-boot hot 2
Bug in org.springframework.boot on 2.2.3.RELEASE version hot 2
"factory already defined" error with spring-boot-maven-plugin in maven multi-module application hot 2
Kafka 2.5.0 with 2.2.6 spring boot - spring-boot hot 2
Github User Rank List