justauth-spring-boot-starter icon indicating copy to clipboard operation
justauth-spring-boot-starter copied to clipboard

Redis Spring Bean Conflict

Open Wenrh2004 opened this issue 8 months ago • 1 comments


APPLICATION FAILED TO START


Description:

Parameter 0 of method authStateCache in com.xkcoding.justauth.autoconfigure.JustAuthStateCacheConfiguration$Redis required a single bean, but 2 were found: - justAuthRedisCacheTemplate: defined by method 'justAuthRedisCacheTemplate' in class path resource [com/xkcoding/justauth/autoconfigure/JustAuthStateCacheConfiguration$Redis.class] - stringRedisTemplate: defined by method 'stringRedisTemplate' in class path resource [org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration.class]

This may be due to missing parameter name information

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

Ensure that your compiler is configured to use the '-parameters' flag. You may need to update both your build tool settings as well as your IDE. (See https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#parameter-name-retention)

Wenrh2004 avatar Apr 21 '25 16:04 Wenrh2004

缓存类型设置为自定义,然后再定义一个 AuthStateCache Bean 即可

@Bean
public AuthStateCache authStateCache(RedisTemplate<String, String> redisTemplate, JustAuthProperties justAuthProperties) {
    return new RedisStateCache(redisTemplate, justAuthProperties.getCache());
}

aboutZZ avatar Aug 15 '25 07:08 aboutZZ