springboot2集成oauth2坑二(The bean 'scopedTarget.oauth2ClientContext', defined in class path resource )

Easter79
• 阅读 799

码云地址:https://gitee.com/lpxs/lp-springcloud.git 有问题可以多沟通:136358344@qq.com。

由于使用Enableoauth2sso注解一直报错,报错原因见上一篇文章《springboot2集成oauth2坑一》 后面换成了@EnableOAuth2Client注解,并自定义了相关配置

 @Bean
    public FilterRegistrationBean oauth2ClientFilterRegistration(OAuth2ClientContextFilter filter) {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(filter);
        registration.setOrder(-100);
        return registration;
    }

    @Bean
    @ConfigurationProperties("security.oauth2")
    public ClientResources trina() {
        return new ClientResources();
    }

启动后会报下面错误:

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:

这个有两种方案: 1、去掉autoconfig依赖spring-security-oauth2-autoconfigure 2、使用@EnableAutoConfiguration来排除掉oauth2相关自动装配,这个得根据具体报错信息来。 如下:

@EnableAutoConfiguration(exclude = {
        org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
})

3、增加配置spring.main.allow-bean-definition-overriding =true

点赞
收藏
评论区
推荐文章
Easter79 Easter79
3年前
springcloud集成grpc(一)
码云地址:https://gitee.com/lpxs/lpspringcloud.git(https://gitee.com/lpxs/lpspringcloud.git)有问题可以多沟通:136358344@qq.com。(https://www.oschina.net/action/GoToLink?urlmailto%3A%E6%
Easter79 Easter79
3年前
springboot2集成oauth2坑一(Possible CSRF detected
码云地址:https://gitee.com/lpxs/lpspringcloud.git(https://gitee.com/lpxs/lpspringcloud.git)有问题可以多沟通:136358344@qq.com。(https://www.oschina.net/action/GoToLink?urlmailto%3A%E6%
Easter79 Easter79
3年前
springcloud集成grpc(二)
码云地址:https://gitee.com/lpxs/lpspringcloud.git(https://gitee.com/lpxs/lpspringcloud.git)有问题可以多沟通:136358344@qq.com。(https://www.oschina.net/action/GoToLink?urlmailto%3A%E6%
Easter79 Easter79
3年前
springcloud经验
\ 码云地址:https://gitee.com/lpxs/lpspringcloud.git\ 有问题可以多沟通:136358344@qq.com。架构演化的步骤
Easter79 Easter79
3年前
SpringSecurityOAuth2(9) feign 微服务间调用 token验证
GitHub地址(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fweizongwu%2FSpringCloudOAuth2SpringSecurityFrame.git"项目地址")码云地址(https://gitee.com/wujishu/
Easter79 Easter79
3年前
SpringSecurityOAuth2(5)自定义登录登出
GitHub地址(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fweizongwu%2FSpringCloudOAuth2SpringSecurityFrame.git"项目地址")码云地址(https://gitee.com/wujishu/
Easter79 Easter79
3年前
SpringSecurityOAuth2(8) swagger2 集成OAuth2
GitHub地址(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fweizongwu%2FSpringCloudOAuth2SpringSecurityFrame.git"项目地址")码云地址(https://gitee.com/wujishu/
Easter79 Easter79
3年前
SpringSecurityOAuth2(3)自定义token信息
GitHub地址(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fweizongwu%2FSpringCloudOAuth2SpringSecurityFrame.git"项目地址")码云地址(https://gitee.com/wujishu/
Easter79 Easter79
3年前
SpringSecurityOAuth2(4)根据请求URI动态权限判断
GitHub地址(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fweizongwu%2FSpringCloudOAuth2SpringSecurityFrame.git"项目地址")码云地址(https://gitee.com/wujishu/
Easter79 Easter79
3年前
SpringSecurityOAuth2(4)根据请求URI动态权限判断(补)
GitHub地址(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fweizongwu%2FSpringCloudOAuth2SpringSecurityFrame.git"项目地址")码云地址(https://gitee.com/wujishu/
Easter79
Easter79
Lv1
今生可爱与温柔,每一样都不能少。
文章
2.8k
粉丝
5
获赞
1.2k