springboot整合J2cache简单使用

第一步

pom.xml文件加入j2cache的依赖

		<dependency>
			<groupId>net.oschina.j2cache</groupId>
			<artifactId>j2cache-spring-boot2-starter</artifactId>
			<version>2.7.2-release</version>
		</dependency>

第二步

从J2cache的gitee地址上复制对应的配置文件(直接copy就好,之后再修改),这里使用 caffeine + redis 的组合,redis客户端使用lettuce。

所需要的配置文件为:
caffeine.properties
j2cache.properties
在这里插入图片描述

第三步

caffeine.properties
不需要修改,默认就好,如果有特殊需要请特定修改!

j2cache.properties

  1. j2cache.broadcast 改为 lettuce
  2. j2cache.L2.provider_class改为 lettuce
  3. caffeine.properties改为自己指定路径(注意检查)
  4. 使用redis、lettuce下的配置 hosts 以及 password

第四步

配置application.yml或者application.properties

j2cache:
  config-location: /config/j2cache.properties  #指定加载j2cache的配置文件路径
  redis-client: lettuce
  open-spring-cache: true

第五步

调用

#错误示范
public class J2CacheUtil {

	private static CacheChannel cache = J2Cache.getChannel();
	......
}
#正确示范
@Component  #必须使用该注解进行注入
public class J2CacheUtil {

    @Autowired
    private CacheChannel cacheChannel;
    ......
}

完!!!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值