Spring-boot使用Ehcache配置
1、配置类
- @Configuration
- @EnableCaching
- public class CacheConfiguration {// implements CachingConfigurer {
- @Bean
- //@Override
- public CacheManager cacheManager() {
- EhCacheCacheManager cacheManager = new EhCacheCacheManager();
- cacheManager.setCacheManager(ehCacheManagerFactoryBean().getObject());
- return cacheManager;
- }
- @Bean
- //@Override
- public KeyGenerator keyGenerator() {
- return new SimpleKeyGenerator();
- }
- @Bean
- public EhCacheManagerFactoryBean ehCacheManagerFactoryBean() {
- EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean();
- ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
- ehCacheManagerFactoryBean.setCacheManagerName("messageCache");
- ehCacheManagerFactoryBean.setShared(true);
- return ehCacheManagerFactoryBean;
- }
- // @Override
- // public CacheResolver cacheResolver() {
- // // TODO Auto-generated method stub
- // return new SimpleCacheResolver();
- // }
- //
- // @Override
- // public CacheErrorHandler errorHandler() {
- // // TODO Auto-generated method stub
- // return new SimpleCacheErrorHandler();
- // }
- }
2、位于resource目录下的配置文件ehcache.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <ehcache>
- <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />
- <cache name="messageCache" maxElementsInMemory="10" eternal="true" overflowToDisk="false" />
- </ehcache>
3、Cache对象
- @Cacheable(value="messageCache")
- public Integer testCashe( String data ) {
- return new Integer(data.length());
- }
注意:Cache对象的value参数要与ehcache.xml配置文件中对应一致。
Spring-boot使用Ehcache配置的更多相关文章
- 【转】spring boot application.properties 配置参数详情
multipart multipart.enabled 开启上传支持(默认:true) multipart.file-size-threshold: 大于该值的文件会被写到磁盘上 multipart. ...
- (37)Spring Boot集成EHCache实现缓存机制【从零开始学Spring Boot】
[本文章是否对你有用以及是否有好的建议,请留言] 写后感:博主写这么一系列文章也不容易啊,请评论支持下. 如果看过我之前(35)的文章这一篇的文章就会很简单,没有什么挑战性了. 那么我们先说说这一篇文 ...
- Spring boot application.properties 配置
原文链接: http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.ht ...
- Spring Boot2 系列教程(三十)Spring Boot 整合 Ehcache
用惯了 Redis ,很多人已经忘记了还有另一个缓存方案 Ehcache ,是的,在 Redis 一统江湖的时代,Ehcache 渐渐有点没落了,不过,我们还是有必要了解下 Ehcache ,在有的场 ...
- Spring Boot缓存Ehcache
Spring Boot 整合 Ehcache 修改 pom 文件 <!-- Spring Boot 缓存支持启动器 --> <dependency> <groupId ...
- 另一种缓存,Spring Boot 整合 Ehcache
用惯了 Redis ,很多人已经忘记了还有另一个缓存方案 Ehcache ,是的,在 Redis 一统江湖的时代,Ehcache 渐渐有点没落了,不过,我们还是有必要了解下 Ehcache ,在有的场 ...
- Spring Boot整合EhCache
本文讲解Spring Boot与EhCache的整合. 1 EhCache简介 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认CacheProvid ...
- spring boot web相关配置
spring boot集成了servlet容器,当我们在pom文件中增加spring-boot-starter-web的maven依赖时,不做任何web相关的配置便能提供web服务,这还得归于spri ...
- 初识Spring Boot框架(二)之DIY一个Spring Boot的自动配置
在上篇博客初识Spring Boot框架中我们初步见识了SpringBoot的方便之处,很多小伙伴可能也会好奇这个Spring Boot是怎么实现自动配置的,那么今天我就带小伙伴我们自己来实现一个简单 ...
- Spring Boot 2.0 配置图文教程
摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠BYSocket 」欢迎关注和转载,保留摘要,谢谢! 本章内容 自定义属性快速入门 外化配置 自动配置 自定义创建 ...
随机推荐
- (Android Studio)添加文本框
此文大部分摘自http://hukai.me/android-training-course-in-chinese/basics/firstapp/building-ui.html android : ...
- ArcGIS 读写lyr层文件
原文arcengine C# 读写lyr(转) 写lyr IFeatureLayer LineLayer = axMapControl1.get_Layer() as IFeatureLayer; I ...
- MVC Razor 语法(转)
http://blog.csdn.net/pasic/article/details/7072340 原文地址:MVC Razor 语法(转)作者:panzhaowen_jacki 语法名称 Razo ...
- Hander
多线程与UI线程间通信 向你展示如何从任务发送数据对象上运行用户界面(UI)线程.该特性允许你的任务做背景的工作结果,然后再到UI元素如位图. 每个应用程序都有自己的特殊的线程运行的UI对象如视图对象 ...
- linux命令getopts
一.getopts 简介 由于shell命令行的灵活性,自己编写代码判断时,复杂度会比较高.使用内部命令 getopts 可以很方便地处理命令行参数.一般格式为: getopts options va ...
- jetty上传 Form too large: 275782 > 200000
1,找到jetty服务器下的jetty.xml,在 <Configure id="Server" class="org.eclipse.jetty.server.S ...
- Linode各机房在中国访问速度性能测试
最近因为google的各种被X的原因,想自己弄个VPS玩玩,比来比去都推荐linode. 因为各种性能测试工具都不靠谱,还是自己机器来的直接,虽然笨拙但是真实可信. 从测试结果上看,明显东京机房的速度 ...
- 可以使用Markdown了?
园子果然领先 1.标题类 一级标题 二级标题 三级标题 四级 六级 怎么可以用#号?上传上去看看 2.换行 第一行 换一行 在换一行 3.多个下划线 the_odd_egg odd 斜体用星号 4.删 ...
- 把存储过程获取的数据输出到报表的html模板中
制作报表的html模板 <HTML><meta http-equiv="Content-Type" content="text/html; charse ...
- KVC, KVO实现原理剖析
iPhone程序开发 KVO/KVC实现机理分析是本文要介绍的内容,不多说,直接进入话题.我们来看详细内容. Objective-C里面的Key-Value Observing (KVO)机制,非常不 ...