我有一个应用程序使用redis作为sesison存储:
@EnableRedisHttpSession
@KeycloakConfiguration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@PropertySource("classpath:auth.properties")
public class config {
@Bean
public static ConfigureRedisAction configureRedisAction() {
return ConfigureRedisAction.NO_OP;
}
}
当使用mockmvc运行单元测试caeses时,它失败,错误如下:
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: {}
我尝试的解决方案是通过在test的application.yml中执行以下配置来禁用单元测试的@enablereditpsession:
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
但它仍在失败,出现同样的错误。有没有人能建议如何解决这个问题,或者有没有其他办法。
暂无答案!
目前还没有任何答案,快来回答吧!