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

标签 java spring spring-boot redis

我要设置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/

相关文章:

java - Hibernate @Version 字段错误

java - 修复无限循环?

java - Xades4J 兼容 PKCS11 native 库中应该包含什么?

java - Spring Boot/Spring Security 根据路径在多个认证提供者之间进行选择

maven - 找不到 SpringApplicationConfiguration : Erroneous spring-boot-starter-test content?

java - Spring Boot 1.4 - 如何使用验证来测试 Controller

java - Android - 点击alertDialog内的按钮

java - Spring认证LDAP示例和真实的LDAP服务器

java - Spring Boot 中的外部 YAML 属性文件和普通属性文件

spring - 如何使用 Spring JMS 访问 FQQN?