首页 > 解决方案 > 无法注册 Bean 'scopedTarget.oauth2ClientContext' 相同的 bean 名称已在类路径中定义

问题描述

我很简单地尝试为我的应用启用谷歌登录功能,但遇到了这个特定的错误。我不明白这个问题为什么我得到它?我需要帮助来解决此错误吗?有什么提示吗?

@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

标签: javaspringspring-bootspring-securityoauth-2.0

解决方案


我遇到了同样的问题。我通过将 spring-security-oauth2-autoconfigure 库的版本升级到 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>

推荐阅读