gpt4 book ai didi

java - 设置springboot启动检查redis,database,mq

转载 作者:可可西里 更新时间:2023-11-01 11:28:57 27 4
gpt4 key购买 nike

我要设置springboot启动检查redis、数据库、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;
}
}

I WANT SET SPRINGBOOT STARTING CHECK REDIS CONNECTION

最佳答案

如果需要使用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:password@example.com: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

关于java - 设置springboot启动检查redis,database,mq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42507066/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com