SecurityConfig 中出现 SpringSecurity + AWS Cognito 连接错误

Posted

技术标签:

【中文标题】SecurityConfig 中出现 SpringSecurity + AWS Cognito 连接错误【英文标题】:SpringSecurity + AWS Cognito connection error occurred in SecurityConfig 【发布时间】:2021-02-03 15:48:38 【问题描述】:

我正在练习 AWS cognito 与 springboot 的链接。 但是,securityconfig 中发生了一个神秘的错误。 我不知道为什么会发生错误。 gradle设置错了吗?

这里是代码。

SecurityConfiguration.class

@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter 

@Override
protected void configure(HttpSecurity http) throws Exception 
    http.csrf()
            .and()
            .authorizeRequests()
            .mvcMatchers("/").permitAll().anyRequest().authenticated()
            .and()
            .oauth2Login()
            .and()
            .logout()
            .logoutSuccessUrl("/");
    

和 CognitoWebConfiguration.class

@Configuration
public class CognitoWebConfiguration implements WebMvcConfigurer 

@Override
public void addViewControllers(ViewControllerRegistry registry) 
    registry.addViewController("/").setViewName("home");
  

和 build.grade 文件

plugins 
id 'org.springframework.boot' version '2.1.16.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'


group = 'jpabook'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'


configurations 
compileOnly 
    extendsFrom annotationProcessor
    



repositories 
mavenCentral()


dependencies 

compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'


implementation 'org.springframework.boot:spring-boot-devtools'


implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.5.6'

compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'


implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
compile group: 'org.springframework.security', name: 'spring-security-oauth2-client', version: '5.3.4.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-oauth2-jose', version: '5.3.4.RELEASE'


testCompile group: 'org.springframework', name: 'spring-test', version: '2.5'
testCompile group: 'org.springframework.security', name: 'spring-security-test', version: '4.0.0.RELEASE'



最后,这是一条错误消息。有点长。

org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“securityConfiguration”的bean时出错:通过方法“setContentNegotationStrategy”参数0表示的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration' 的 bean 时出错:通过方法 'setConfigurers' 参数 0 表达的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为 'org.springframework.security.config.annotation.web.configuration.OAuth2ClientConfiguration$OAuth2ClientWebMvcSecurityConfiguration' 的 bean 时出错:通过方法 'setClientRegistrationRepository' 参数 0 表达的不满足依赖关系;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.class] 中定义名称为“clientRegistrationRepository”的 bean 创建时出错:Bean 实例化通过工厂方法失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository]:工厂方法“clientRegistrationRepository”抛出异常;嵌套异常是 java.lang.NoSuchFieldError: PASSWORD 在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:678) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:376) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1402) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:591) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:863) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.16.RELEASE.jar:2.1.16.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) ~[spring-boot-2.1.16.RELEASE.jar:2.1.16.RELEASE] 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) ~[spring-boot-2.1.16.RELEASE.jar:2.1.16.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-2.1.16.RELEASE.jar:2.1.16.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.1.16.RELEASE.jar:2.1.16.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) ~[spring-boot-2.1.16.RELEASE.jar:2.1.16.RELEASE] 在 jpabook.jpashop.JpashopApplication.main(JpashopApplication.java:13) ~[main/:na] 在 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] 在 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] 在 java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] 在 java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] 在 org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.1.16.RELEASE.jar:2.1.16.RELEASE] 原因:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration”的bean时出错:通过方法“setConfigurers”参数0表示的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为 'org.springframework.security.config.annotation.web.configuration.OAuth2ClientConfiguration$OAuth2ClientWebMvcSecurityConfiguration' 的 bean 时出错:通过方法 'setClientRegistrationRepository' 参数 0 表达的不满足依赖关系;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.class] 中定义名称为“clientRegistrationRepository”的 bean 创建时出错:Bean 实例化通过工厂方法失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository]:工厂方法“clientRegistrationRepository”抛出异常;嵌套异常是 java.lang.NoSuchFieldError: PASSWORD 在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:678) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:376) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1402) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:591) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:392) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1318) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1158) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:554) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1273) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1193) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:670) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] ...省略了24个常用框架 原因:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“org.springframework.security.config.annotation.web.configuration.OAuth2ClientConfiguration$OAuth2ClientWebMvcSecurityConfiguration”的bean时出错:通过方法“setClientRegistrationRepository”参数0表示的不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.class] 中定义名称为“clientRegistrationRepository”的 bean 创建时出错:Bean 实例化通过工厂方法失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository]:工厂方法“clientRegistrationRepository”抛出异常;嵌套异常是 java.lang.NoSuchFieldError: PASSWORD 在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:678) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:376) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1402) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:591) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1489) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1453) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1344) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1231) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1193) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:670) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] ...省略了46个常用框架 原因:org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.class] 中定义名称为“clientRegistrationRepository”的 bean 创建错误:Bean 实例化通过工厂方法失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository]:工厂方法“clientRegistrationRepository”抛出异常;嵌套异常是 java.lang.NoSuchFieldError: PASSWORD 在 org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1318) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1158) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:554) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1489) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1453) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1344) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1231) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1193) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:670) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] ...省略了62个常用框架 原因:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository]:工厂方法'clientRegistrationRepository'抛出异常;嵌套异常是 java.lang.NoSuchFieldError: PASSWORD 在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] ...省略了78个常用框架 引起:java.lang.NoSuchFieldError: PASSWORD 在 org.springframework.security.oauth2.client.registration.ClientRegistration$Builder.build(ClientRegistration.java:523) ~[spring-security-oauth2-client-5.3.4.RELEASE.jar:5.3.4.RELEASE] 在 org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getClientRegistration(OAuth2ClientPropertiesRegistrationAdapter.java:74) ~[spring-boot-autoconfigure-2.1.16.RELEASE.jar:2.1.16.RELEASE] 在 org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.lambda$getClientRegistrations$0(OAuth2ClientPropertiesRegistrationAdapter.java:53) ~[spring-boot-autoconfigure-2.1.16.RELEASE.jar:2.1.16.RELEASE] 在 java.base/java.util.HashMap.forEach(HashMap.java:1336) ~[na:na] 在 org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(OAuth2ClientPropertiesRegistrationAdapter.java:52) ~[spring-boot-autoconfigure-2.1.16.RELEASE.jar:2.1.16.RELEASE] 在 org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientRegistrationRepositoryConfiguration.clientRegistrationRepository(OAuth2ClientRegistrationRepositoryConfiguration.java:55) ~[spring-boot-autoconfigure-2.1.16.RELEASE.jar:2.1.16.RELEASE] 在 org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientRegistrationRepositoryConfiguration$$EnhancerBySpringCGLIB$$86e7f9b3.CGLIB$clientRegistrationRepository$0() ~[spring-boot-autoconfigure-2.1.16.RELEASE.jar:2.1.16 。发布] 在 org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientRegistrationRepositoryConfiguration$$EnhancerBySpringCGLIB$$86e7f9b3$$FastClassBySpringCGLIB$$d8c711b.invoke() ~[spring-boot-autoconfigure-2.1.16.RELEASE.jar: 2.1.16.发布] 在 org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.17.RELEASE.jar:5.1.17.RELEASE] 在 org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientRegistrationRepositoryConfiguration$$EnhancerBySpringCGLIB$$$86e7f9b3.clientRegistrationRepository() ~[spring-boot-autoconfigure-2.1.16.RELEASE.jar:2.1.16.RELEASE] 在 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] 在 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] 在 java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] 在 java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] 在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.17.RELEASE.jar:5.1.17.RELEASE] ...省略了79个常用框架

有人帮帮我..!

【问题讨论】:

【参考方案1】:

问题是依赖。 build.gradle中springboot版本改为2.3.4.RELEASE并激活。

【讨论】:

以上是关于SecurityConfig 中出现 SpringSecurity + AWS Cognito 连接错误的主要内容,如果未能解决你的问题,请参考以下文章

尽管有 SecurityConfig,但 Spring Security 会阻止 POST 请求

Spring SecurityConfig 不起作用

UnsatisfiedDependencyException:创建名为“securityConfig”的 bean 时出错

创建名为“securityConfig”的 bean 时出错:注入自动装配的依赖项失败

Spring Security入门(2-3)HttpSecurity的使用

在 grails + acegi 中测试 securityConfig 映射