spring boot 调用ehcache3.x(jsr107接口)原生api
来源:互联网 发布:深圳sem优化 编辑:程序博客网 时间:2024/06/05 17:39
有时候,spring cache的注解可能没有满足我们的需求,这时候就要考虑使用原生API了!其实原理很简单,就是把cache交给spring容器托管就好。废话少说上代码:(注意:当前的该文是基于spring boot spring cache ehcache3.x整合)
@Configuration@EnableCachingpublic class CacheConfig { /** * 托管在配置文件ehcache.xml定义的Cache * @param cacheManager * @return */ @Bean public Cache<String,String> cityCache(CacheManager cacheManager) { return cacheManager.getCache("city"); } /** * 托管在配置文件ehcache.xml定义的Cache * @param cacheManager * @return */ @Bean public Cache<String,String> userCache(CacheManager cacheManager) { return cacheManager.getCache("user"); }}
使用例子:
import javax.cache.Cache;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.CommandLineRunner;public class StartupRunner implements CommandLineRunner { @Autowired private Cache<String,String> cityCache; @Autowired private Cache<String,String> userCache; @Override public void run(String... strings) throws Exception { cityCache.put("userName","liangrh"); userCache.put("userName","liangrh"); }}
Over…
1 0
- spring boot 调用ehcache3.x(jsr107接口)原生api
- spring boot spring cache ehcache3.x整合
- Spring Boot学习总结(9)——SpringBoot集成Ehcache3.x
- Spring Boot整合ehcache3.0 缓存
- spring cache 应用Jcache和ehcache3.x 实践
- Spring-Boot -- RESTFUL风格的API接口的三种调用方式【测试】
- Spring Boot使用方法小札(4):使用Serlvet中原生Filter API
- spring boot中用RabbitMQ调用接口
- spring boot 调用接口超时解决 HystrixRuntime
- Spring MVC 使用Servlet原生API作为参数,在 spring boot 、 spring cloud 同样适用。
- Spring-Boot + Swagger2 自动生成API接口文档
- Spring Boot学习(RESTful API)
- spring boot API 完整版
- unity调用android原生接口
- spring-boot restful接口学习(1)
- spring-boot集成swagger(接口管理工具)
- Spring中使用RestTemplate调用第三方接口API
- spring boot 原生错误处理ErrorController
- iOS开发:面向协议编程与 Cocoa 的邂逅 (下)
- SourceTree里GitFlow的使用
- IntelliJ IDEA java工程如何添加jar
- ios-基础之【13】-iOS的@property的详细解读
- POI 导出Excel 时间格式和小数点数据的处理
- spring boot 调用ehcache3.x(jsr107接口)原生api
- 哈希算法以及解决哈希冲突
- xcode 8.1 插件不能安装的问题。
- 数据结构之树、森林和二叉树的转换
- mybatis 批量操作
- css3 2d skew()方法用法理解
- 中科每时每客WiFi客流系统首次配置教程
- Spring MVC 自定义方法参数注入
- jquery validate提示错误信息位置修改