Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bean 'scopedTarget.oauth2ClientContext' could not be registered same bean name has already been defined in class path

I am simple trying to enable google sign in feature for my app but getting this particular error. I don't understand this problem why I am getting it? I need help to fix this error? Any hints?

@Configuration
@EnableOAuth2Sso
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf()
                    .disable()
                .antMatcher("/**")
                .authorizeRequests()
                .antMatchers("/", "/welcomepage")
                    .permitAll()
                .anyRequest()
                .authenticated();
    }
}

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

Description:

The bean 'scopedTarget.oauth2ClientContext', defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration$SessionScopedConfiguration$ClientContextConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/security/oauth2/config/annotation/web/configuration/OAuth2ClientConfiguration$OAuth2ClientContextConfiguration.class] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
like image 917
bmalhi Avatar asked Dec 16 '18 00:12

bmalhi


People also ask

How do I get OAuth2ClientContext?

As per the Spring documentation you can simply add @EnableOAuth2Client and Spring Boot will create an OAuth2ClientContext for you.

What is OAuth2RestTemplate?

The main goal of the OAuth2RestTemplate is to reduce the code needed to make OAuth2-based API calls. It basically meets two needs for our application: Handles the OAuth2 authentication flow. Extends Spring RestTemplate for making API calls.


1 Answers

I had encountered the same issue. I resolved it by upgrading the version of spring-security-oauth2-autoconfigure library to 2.1.1.RELEASE.

    <dependency>
        <groupId>org.springframework.security.oauth.boot</groupId>
        <artifactId>spring-security-oauth2-autoconfigure</artifactId>
        <version>2.1.1.RELEASE</version>
    </dependency>
like image 112
Filip Wielkopolan Avatar answered Oct 05 '22 11:10

Filip Wielkopolan