Круговой конфликт зависимостей Spring Boot между Spring Boot Security, JPA, Web MVC и Cache - PullRequest
2 голосов
/ 12 февраля 2020

Создание веб-приложения для весенней загрузки с подключением к базе данных JPA. Работает нормально до сих пор. Теперь при реализации Spring Boot Security с внутренней библиотекой компании, которая обогащает исходную зависимость безопасности Spring, я столкнулся с проблемой циклической зависимости.

Консоль:

***************************
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]
└─────┘

Класс SecurityConfig:

@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-компонентами в консоли?

EDIT 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
...