модульный тест Redis как хранилище данных сеанса - PullRequest
0 голосов
/ 17 июня 2020

У меня есть приложение, которое использует redis в качестве хранилища сессий:

@EnableRedisHttpSession
@KeycloakConfiguration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@PropertySource("classpath:auth.properties")
public class config {

@Bean
    public static ConfigureRedisAction configureRedisAction() {
        return ConfigureRedisAction.NO_OP;
    }
}

при запуске модульных тестов с использованием mock mvc оно не работает с ошибкой ниже:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
'org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration$SessionCleanupConfiguration':
Unsatisfied dependency expressed through constructor parameter 0; 
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration':
Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type 'org.springframework.data.redis.connection.RedisConnectionFactory' available:
expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

Решение, которое я пытался, - отключить @EnableRedisHttpSession для модульных тестов, выполнив приведенную ниже конфигурацию в test application.yml:

spring:
  session:
    store-type: none
  main:
    allow-bean-definition-overriding: true
  data:
    redis:
      repositories:
        enabled: false
  autoconfigure:
    exclude:
    - org.springframework.boot.autoconfigure.session.SessionAutoConfiguration
    - org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
    - org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration

, но он все еще не работает с той же ошибкой. может ли кто-нибудь предложить, как решить эту проблему, или есть ли другой подход.

...