// Spring Boot auto-configures the cache infrastructure as long as caching support is enabled via the @EnableCaching annotation @EnableCaching @Configuration publicclassRedisConfiguration{ @Bean public RedisCacheManager cacheManager(RedisTemplate<String, String> redisTemplate){ RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplate); RedisSerializer<String> keyRedisSerializer = new StringRedisSerializer(); RedisSerializer<Object> valueRedisSerializer = new GenericJackson2JsonRedisSerializer(); redisTemplate.setKeySerializer(keyRedisSerializer); redisTemplate.setValueSerializer(valueRedisSerializer); redisTemplate.afterPropertiesSet(); redisCacheManager.setUsePrefix(true); //默认过期时间2小时 redisCacheManager.setDefaultExpiration(7200); return redisCacheManager; } }