Vin*_*t F 5 java spring-security spring-boot springdoc
将我的应用程序从 Spring Boot 2.5 升级到 2.6 时,出现此错误:
创建名称为“securityConfig”的 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.springdoc.ui.SwaggerConfig”的bean时出错:通过字段“swaggerIndexTransformer”表达的依赖关系不满足;
嵌套异常是org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名称为“org.springdoc.ui.SwaggerConfig”的bean时出错:请求的bean当前正在创建中:是否存在无法解析的循环引用?
此错误记录在https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6-Release-Notes#circular-references-prohibited-by-default上,我知道我可以“修复”通过设置一个属性并返回到 Spring Boot 2.5 行为来实现它。但是如果我可以借此机会修复循环引用,我也可以在将来这样做。
我的securityConfig
很简单,因为我的应用程序是一个公共应用程序,向所有调用者返回一些 html 内容,无需身份验证。这是我的配置:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity security) throws Exception {
//application is open to everyone - no security
security.httpBasic().disable();
}
}
Run Code Online (Sandbox Code Playgroud)
setContentNegotationStrategy
错误提到的方法是我WebSecurityConfigurerAdapter
没有覆盖的方法,所以我无法理解我需要做什么。
如果我删除我的SecurityConfig
课程,那么我仍然有一个错误,与以前相同,但没有提及我的SecurityConfig
课程:
创建名称为“org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration”的bean时出错:通过方法“setConfigurers”参数0表示不满足的依赖关系;
嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“org.springdoc.ui.SwaggerConfig”的bean时出错:通过字段“swaggerIndexTransformer”表达的依赖关系不满足;
嵌套异常是org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名称为“org.springdoc.ui.SwaggerConfig”的bean时出错:请求的bean当前正在创建中:是否存在无法解析的循环引用?
处理 Spring Security 和 org.springdoc.ui.SwaggerConfig 之间的循环引用的推荐方法是什么?