2017-02-28 6 views
0

私がチェックRedisのを開始springbootを設定したい、データベース、MQ接続セットチェックRedisのを開始springboot、データベース、MQ

@Configuration 
@EnableCaching 
public class RedisConfig extends CachingConfigurerSupport { 
    @Bean 
    public CacheManager cacheManager(@SuppressWarnings("rawtypes") RedisTemplate redisTemplate) { 
     return new RedisCacheManager(redisTemplate); 
    } 
    @Bean 
    public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) { 
     StringRedisTemplate template = new StringRedisTemplate(factory); 
     Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); 
     ObjectMapper om = new ObjectMapper(); 
     om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); 
     om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); 
     jackson2JsonRedisSerializer.setObjectMapper(om); 
     template.setValueSerializer(jackson2JsonRedisSerializer); 
     template.afterPropertiesSet(); 
     return template; 
    } 
} 

あなたが必要な場合は、私がSET SPRINGBOOT開始チェックRedisのをCONNECTION

答えて

0

をしたいですapplication.propertiesを使用してredis接続を設定します。フロープロパティをapplication.propertiesに追加してください。

spring.redis.database=0 # Database index used by the connection factory. 
spring.redis.url= # Connection URL, will override host, port and password (user will be ignored), e.g. redis://user:[email protected]:6379 
spring.redis.host=localhost # Redis server host. 
spring.redis.password= # Login password of the redis server. 

詳細については、Springのドキュメントを参照してください。

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

関連する問題