springboot+redis+shiro導致快取註解無效?
阿新 • • 發佈:2018-12-20
根據“在整合springboot/shiro/redis 時,發現@Cacheable註解失效,如何解決?”處理springboot-shiro-redis自定義redis快取註解不進入aop問題? (1) 在ShiroRealm中userService上加入@Lazy註解 (2) Redistemplate能存值但是取不到值 RedisTemplate<String, Object> template = new RedisTemplate<>(); template.setConnectionFactory(redisConnectionFactory); // 使用Jackson2JsonRedisSerialize 替換預設序列化 Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); jackson2JsonRedisSerializer.setObjectMapper(objectMapper); // 設定value的序列化規則和 key的序列化規則 template.setKeySerializer(new StringRedisSerializer()); template.setValueSerializer(jackson2JsonRedisSerializer); template.afterPropertiesSet();