redis maven java_Maven+SSM使用redis做缓存 Spring5(JavaConfig注解配置)

1. 配置环境Redis 4 安装教程自行google

Spring 5.0.9

Mybatis 3.4.6

2. 依赖

注意:默认你配置好了SSM的依赖环境,我只说在SSM配好过后怎么把redis加进去

我用的依赖是如下的版本,基本都没有最新jar包的教程,网上的老教程千奇百怪,真的是痛心。

如果你不是用的spring-data-redis的2.X的版本你可以不用看了,看了也没用。

2.9.0

2.1.0.RELEASE

redis.clients

jedis

${jedis.version}

org.springframework.data

spring-data-redis

${redis.version}

3.配置

首先是redisConfig.java,哇,这个是真的一个巨坑,改动贼多。老教程根本无法使用。作为一个新手瑟瑟发抖。不多说了,先贴代码,再解释import org.springframework.beans.factory.annotation.Value;import org.springframework.cache.annotation.EnableCaching;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.PropertySource;import org.springframework.data.redis.cache.RedisCacheManager;import org.springframework.data.redis.connection.*;import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;import org.springframework.data.redis.core.RedisTemplate;import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;import org.springframework.data.redis.serializer.StringRedisSerializer;import redis.clients.jedis.JedisPool;import redis.clients.jedis.JedisPoolConfig;@Configuration@PropertySource("classpath:config/redis.properties")@EnableCachingpublic class RedisConfig {    @Value("${redis.maxTotal}")    private int maxTotal;    @Value("${redis.maxIdle}")    private int maxIdle;    @Value("${redis.maxWaitMillis}")    private long maxWaitMillis;    @Value("${redis.testOnBorrow}")    private boolean testOnBorrow;    @Value("${redis.host}")    private String host;    @Value("${redis.port}")    private int port;    @Value("${redis.timeout}")    private int timeout;    @Value("${redis.password}")    private String password;    @Value("${redis.database}")    private int database;    @Value("${redis.minEvictableIdleTimeMillis}")    private int minEvictableIdleTimeMillis;    @Value("${redis.softMinEvictableIdleTimeMillis}")    private int softMinEvictableIdleTimeMillis;    @Value("${redis.timeBetweenEvictionRunsMillis}")    private int timeBetweenEvictionRunsMillis;    @Value("${redis.numTestsPerEvictionRun}")    private int numTestsPerEvictionRun;    @Value("${r

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值