禁用Spring Security 将导致无法加载应用程序上下文

8cdiaqws  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(417)

我正在禁用测试配置文件的Spring Security ,如下所示:

spring:
  config:
    activate:
      on-profile: test
  autoconfigure:
    exclude[0]: org.springframework.boot.actuate.autoconfigure.security.reactive.ReactiveManagementWebSecurityAutoConfiguration
    exclude[1]: org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration

错误:

Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/client/reactive/ReactiveOAuth2ClientConfigurations$ReactiveOAuth2ClientConfiguration$SecurityWebFilterChainConfiguration.class]: Unsatisfied dependency expressed through method 'springSecurityFilterChain' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.config.web.server.ServerHttpSecurity' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
axkjgtzd

axkjgtzd1#

有一点需要澄清的是,您没有禁用SpringSecurity,而是禁用了SpringSecurity的SpringBoot自动配置。您可以在spring引导参考文档中阅读更多关于这方面的内容。
在您的配置中,您正在禁用 ReactiveSecurityAutoConfiguration ,但 ReactiveOAuth2ClientAutoConfiguration 仍然启用,可能是因为您有一个依赖项,例如 spring-boot-starter-oauth2-client .
如错误消息中所述 ReactiveOAuth2ClientAutoConfiguration 正在尝试创建一个 SecurityWebFilterChain bean,但无法注入所需的 ServerHttpSecurity 豆子,因为 ReactiveSecurityAutoConfiguration 它是残疾的。
要修复错误消息,还可以禁用oauth 2.0客户端自动配置。

spring:
 autoconfigure:
    exclude[0]: org.springframework.boot.actuate.autoconfigure.security.reactive.ReactiveManagementWebSecurityAutoConfiguration
    exclude[1]: org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration
    exclude[2]: org.springframework.boot.autoconfigure.security.oauth2.client.reactive.ReactiveOAuth2ClientAutoConfiguration

相关问题