springboot2集成oauth2坑二(The bean 'scopedTarget.oauth2ClientContext', defined in class path resource )
2019-07-29 09:29
2066 查看
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
码云地址: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
相关文章推荐
- Error creating bean with name 'entityManagerFactory' defined in class path resource
- 解决错误Error creating bean with name 'MySessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationC
- Error creating bean with name 'cxf' defined in class path resource [META-INF/cxf/cxf.xml]
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xm
- Error creating bean with name 'sessionFactory' defined in class path resource
- The bean 'counterFactory', defined in class path resource [org/springframework/cloud/netflix/zuul/Zu
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]
- 解决The bean 'proxyRequestHelper', defined in class path resource [org/springframework/cloud/报错
- 【解决】SpringMVC整合Shiro之 Error creating bean with name 'shiroFilter' defined in class path resource...
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xm
- 一、Error creating bean with name 'hsFactory' defined in class path resource [xxx.xml]:
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xm
- Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]:
- SSH搭建时的错误之(1) Error creating bean with name 'testService' defined in class path resource
- 错误Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.
- Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xm
- Hibernate自动生成映射文件有错误Error creating bean with name 'sessionFactory' defined in class path resource
- Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource
- SpringBoot异常:Error creating bean with name 'entityManagerFactory' defined in class path resource