栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring Redis-从application.properties文件读取配置

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Redis-从application.properties文件读取配置

您可以用来

@PropertySource
从application.properties或所需的其他属性文件中读取选项。请查看PropertySource用法示例和用法spring-redis-
cache的
工作示例。或看看这个小样本:

@Configuration@PropertySource("application.properties")public class SpringSessionRedisConfiguration {    @Value("${redis.hostname}")    private String redisHostName;    @Value("${redis.port}")    private int redisPort;    @Bean    public static PropertySourcesPlaceholderConfigurer    propertySourcesPlaceholderConfigurer() {        return new PropertySourcesPlaceholderConfigurer();    }    @Bean    JedisConnectionFactory jedisConnectionFactory() {        JedisConnectionFactory factory = new JedisConnectionFactory();        factory.setHostName(redisHostName);        factory.setPort(redisPort);        factory.setUsePool(true);        return factory;    }    @Bean    RedisTemplate<Object, Object> redisTemplate() {        RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<Object, Object>();        redisTemplate.setConnectionFactory(jedisConnectionFactory());        return redisTemplate;    }    @Bean    RedisCacheManager cacheManager() {        RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplate());        return redisCacheManager;    }}

当前( 2015年12月 )中的 spring.redis.sentinel
选项

application.properties
仅提供
RedisSentinelConfiguration
以下有限的支持:

请注意,当前只有Jedis和生菜生菜支持Redis
Sentinel。

您可以在官方文档中阅读有关此内容的更多信息。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/399410.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号