java - Spring Boot Security、JPA、WebMVC和Cache之间的Spring Boot循环依赖冲突
问题描述
使用 JPA 数据库连接构建 Web Spring Boot 应用程序。到目前为止工作正常。现在,当使用公司内部库实现 Spring Boot Security 时,该库丰富了原始 Spring Security 依赖项,我开始面临循环依赖问题。
安慰:
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
servletEndpointRegistrar defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]
↓
cachesEndpoint defined in class path resource [org/springframework/boot/actuate/autoconfigure/cache/CachesEndpointAutoConfiguration.class]
┌─────┐
| cacheManager defined in class path resource [org/springframework/boot/autoconfigure/cache/CaffeineCacheConfiguration.class]
↑ ↓
| cacheManagerCustomizers defined in class path resource [org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.class]
↑ ↓
| jwtAppSecurityConfigurer (field private org.springframework.security.authentication.AuthenticationManager internal.company.library.package.AbstractPreAuthSecurityConfigurer.authenticationManager)
↑ ↓
| securityConfig (This is my SecurityConfig Class posted below)
↑ ↓
| org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration
↑ ↓
| openEntityManagerInViewInterceptorConfigurer defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration$JpaWebConfiguration.class]
↑ ↓
| openEntityManagerInViewInterceptor defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration$JpaWebConfiguration.class]
└─────┘
安全配置类:
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
// This bean is created by internal spring authentication library
@Autowired
private JwtAppSecurityConfigurer jwtAppSecurityConfigurer;
// Authorize everyone and everything for the moment
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.authorizeRequests().antMatchers("/*").permitAll();
// Apply jwtAppSecurityConfigurer
jwtAppSecurityConfigurer.configure(httpSecurity);
}
// Exposing AuthenticationManager needed by internal library
@Bean(name = BeanIds.AUTHENTICATION_MANAGER)
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
到目前为止我尝试了什么:
公司中提供图书馆的团队到目前为止还不能,但我认为这不是他们提供的图书馆的问题。而是我配置/使用错误的东西。
注释方法、类或整个项目以使用 @Lazy 不起作用
删除与 JPA 相关的所有内容以及依赖项并再次编译项目(但显然会带来其他问题)
设置 application.properties
#spring.cache.type=NONE
也使项目再次编译(但显然带来了其他问题)
任何人都知道我可以做些什么来打破控制台中提到的 bean 之间的循环依赖关系?
编辑1:
application.properties(仅显示 JAP/数据库相关配置):
# ===============================
# = DATA SOURCE
# ===============================
# HikariCP settings
spring.datasource.hikari.connection-timeout=60000
spring.datasource.hikari.maximum-pool-size=5
# database connection config
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url= XXXXXXXXXX
# User and PW currently hard coded
spring.datasource.username= XXXXXXXXXX
spring.datasource.password= XXXXXXXXX
# Keep db connection alive
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
# logging
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
logging.level.org.hibernate.SQL=debug
org.springframework.beans.factory=ALL
# ===============================
# = JPA / HIBERNATE
# ===============================
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=false
spring.jpa.hibernate.ddl-auto=none
#Naming Strategy
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl
spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
# spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
解决方案
推荐阅读
- angular - Angular中模块之间的路由
- python - 从包含对象的列表中获取数据
- ckeditor - InsertHtml 在错误的位置添加指向 ckeditor 的链接
- dialogflow-es - DialogFlow 电话网关国家代码
- r - 在响应式语句中使用扫描
- javascript - 如何使用 javascript 和 css 从选择框选项中删除焦点
- javascript - 在解析阶段,我在 JSDoc 给出的 JS 代码中找不到我的“意外令牌错误”
- python - 通过键盘输入关闭 plt.show()
- spring-boot - 如何根据激活的弹簧配置文件从 kubernetes configMap 加载属性
- java - Hashmap 搜索中的 Hashmap