【发布时间】:2014-07-16 15:17:39
【问题描述】:
当我使用 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 都应该设置为禁用安全性。
如果我的理解有误,有人可以告诉我吗?
【问题讨论】:
-
如果您只想禁用所有内容,为什么还需要对类路径进行安全保护?无论如何,您的堆栈跟踪是不完整的,因此无法知道是什么阻止了应用程序启动。我希望它会启动,但执行器端点应该保持安全,直到您明确打开它们。
-
@DaveSyer 我想暂时禁用安全性,而且我的应用程序代码引用了安全 jar 来工作。
-
您还没有发布足够的信息来了解应用程序无法启动的原因。完整的堆栈跟踪将是一个开始。
-
@DaveSyer 一个原因是管理 spring-sec-oauth2
ClientDetails的微服务。您将拥有 spring-security 的传递导入,但可能不希望在您的服务中使用基本身份验证。
标签: spring-security spring-boot