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 」欢迎关注和转载,保留摘要,谢谢! 本章内容 自定义属性快速入门 外化配置 自动配置 自定义创建 ...
随机推荐
- ln (link)命令
ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同步的链接.当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在 ...
- JS兼容性处理
百度 - 终端适配API 适合服务器端使用.POST客户端传递的http头信息越多,得到的适配信息越准确.百度返回的数据为: 正确情况: { device_type :/*1:手机2:pc*/ os: ...
- codeforce 609A - USB Flash Drives
排序水题 #include<iostream> #include<cstdlib> #include<cstdio> #include<algorithm&g ...
- 在PHPmyadmin中删除数据库
删除数据库用sql语句 的方法: 删除数据库DROP DATABASE `数据库名称`; 删除数据库里的表DROP TABLE `数据库里的表名`;
- Storm入门
Storm框架入门 1 Topology构成 和同样是计算框架的Mapreduce相比,Mapreduce集群上运行的是Job,而Storm集群上运行的是Topology.但是Job在运行结束之后会自 ...
- Sort--冒泡排序
冒泡排序 public class BubbleSort { public static void bubblesort(int[] a){ for(int i=0;i<a.length-1;i ...
- 卸载redhat6.5的yum,安装centos6的yum,配置第三方yum源
**redhat的yum在线更新是收费的,如果没有注册的话不能使用,如果要使用,需将redhat的yum卸载后,重启安装其他yum源,再配置其他源.** 本文包括配置本地源及第三方源.第三方源包括:网 ...
- c# DataTable中使用排序的时候注意事项
背景: 在项目使用DataTable的时候,使用到了其中ExtendedProperties的属性,但是之后出了问题:在排序之后ExtendedProperties的自定义的键值丢失了,代码如下: 误 ...
- ubuntu免验证登陆权限问题
由于经常ssh到服务器,每次输入密码很烦.就传了本机公钥到服务器. 和所有教程将的一样,做起来挺简单的. 本机ssh-keygen -t rsa生成公钥和密钥. 将公钥传至服务器,用户目录下.ssh/ ...
- Java网络编程(TCP协议-练习-上传文本文件)
客户端: package WebProgramingDemo; import java.io.BufferedReader; public class UploadTextClient { /** * ...