当我使用 security.basic.enabled=false 禁用具有以下依赖项的 Spring Boot 项目的安全性时:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
我看到以下 异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.ManagementSecurityAutoConfiguration$ManagementWebSecurityConfigurerAdapter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setObjectPostProcessor(org.springframework.security.config.annotation.ObjectPostProcessor); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.config.annotation.ObjectPostProcessor] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
为了修复这个异常,我必须添加属性 management.security.enabled=false 。我的理解是,当执行器在类路径中时, security.basic.enabled=false 和 management.security.enabled=false 都应该设置为禁用安全性。
如果我的理解有误,有人可以告诉我吗?
原文由 user3600073 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果你的包中有 spring-boot-actuator,你应该添加以下内容
对于较旧的 Spring-boot,该类被称为
ManagementSecurityAutoConfiguration
。在较新的版本中,这已更改为
更新
如果对于反应式应用程序您遇到同样的问题,您可以排除以下类