无法注册Bean'scopedTarget.oauth2ClientContext',因为在类路径中已经定义了相同的Bean名称

时间:2018-12-16 00:33:30

标签: java spring spring-boot spring-security oauth-2.0

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

@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

3 个答案:

答案 0 :(得分:9)

我遇到了同样的问题。我通过将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>

答案 1 :(得分:2)

我遇到了相同的问题,并已解决
只需将版本从2.0.0.RELEASE更改为2.1.1.Rspring的spring-security-oauth2-autoconfigure

答案 2 :(得分:2)

SpringBoot通常会覆盖旧的Bean,但这在Springboot 2.0中有所改变,对我来说spring.main.allow-bean-definition-overriding: true是我应用程序中的第一行。