http://stackoverflow.com/questions/21944202/using-ehcache-in-spring-4-without-xml

1、Ehcache配置类

@Configuration
@EnableCaching
public class CachingConfig implements CachingConfigurer {
@Bean(destroyMethod="shutdown")
public net.sf.ehcache.CacheManager ehCacheManager() {
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setName("myCacheName");
cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
cacheConfiguration.setMaxEntriesLocalHeap(1000); net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
config.addCache(cacheConfiguration); return net.sf.ehcache.CacheManager.newInstance(config);
} @Bean
@Override
public CacheManager cacheManager() {
return new EhCacheCacheManager(ehCacheManager());
} @Bean
@Override
public KeyGenerator keyGenerator() {
return new SimpleKeyGenerator();
}
}

2、调试简单配置类

@Configuration
@EnableCaching
public class CachingConfig implements CachingConfigurer {
@Bean
@Override
public CacheManager cacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager(); List<Cache> caches = new ArrayList<Cache>();
caches.add(new ConcurrentMapCache("myCacheName"));
cacheManager.setCaches(caches); return cacheManager;
} @Bean
@Override
public KeyGenerator keyGenerator() {
return new SimpleKeyGenerator();
}
}

spring-boot + Ehcache without XML的更多相关文章

  1. Spring boot 配置 mybatis xml和动态SQL 分页配置

    更新时间 2018年4月30日23:27:07 1.pom.xml <?xml version="1.0" encoding="UTF-8"?> & ...

  2. Spring Boot中扩展XML请求和响应的支持

    在Spring Boot中,我们大多时候都只提到和用到了针对HTML和JSON格式的请求与响应处理.那么对于XML格式的请求要如何快速的在Controller中包装成对象,以及如何以XML的格式返回一 ...

  3. spring boot(14)-pom.xml配置

    继承spring-boot-starter-parent 要成为一个spring boot项目,首先就必须在pom.xml中继承spring-boot-starter-parent,同时指定其版本 & ...

  4. spring boot的pom.xml配置,正确生成jar包

    spring boot生成的jar包提示没有主清单属性. 需要在pom里加入配置. <?xml version="1.0" encoding="UTF-8" ...

  5. Spring Boot (15) pom.xml设置

    继承spring-boot-parent 要成为一个spring boot项目,首先就必须在pom.xml中继承spring-boot-starter-parent,同时制定其版本 <paren ...

  6. spring boot系列(六)spring boot 配置mybatis(xml简化版)

    orm框架的本质是简化编程中操作数据库的编码,发展到现在基本上就剩两家了,一个是宣称可以不用写一句SQL的hibernate,一个是可以灵活调试动态sql的mybatis,两者各有特点,在企业级系统开 ...

  7. Spring boot 配置 log4j2.xml

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...

  8. SpringBoot零XML配置的Spring Boot Application

    Spring Boot 提供了一种统一的方式来管理应用的配置,允许开发人员使用属性properties文件.YAML 文件.环境变量和命令行参数来定义优先级不同的配置值.零XML配置的Spring B ...

  9. [Spring boot] web应用返回jsp页面

    同事创建了一个spring boot项目,上传到svn.需要我来写个页面.下载下来后,始终无法实现在Controller方法中配置直接返回jsp页面. 郁闷了一下午,终于搞定了问题.在此记录一下. 目 ...

  10. 【原】spring boot在整合项目依赖的问题

    最近要开发新的项目,就花了几天时间看了下spring boot的相关资料,然后做了一个demo,不得不说开发效率确实很快,几行注解就完成了事务,aop,数据库等相关配置:但由于先前习惯了spring ...

随机推荐

  1. 用Apache Kafka构建流数据平台

    近来,有许多关于“流处理”和“事件数据”的讨论,它们往往都与像Kafka.Storm或Samza这样的技术相关.但并不是每个人都知道如何将这种技术引入他们自己的技术栈.于是,Confluent联合创始 ...

  2. 关于触发器、存储过程和DBlink的综合运用 (转)

    关于触发器.存储过程和DBlink的综合运用 需求描述: 需要在两个不同oracl数据库实例中进行数据逻辑处理.如果A实例中的表有新数据插入或者数据更新,那么在B实例中执行与之相关的存储过程. 先假设 ...

  3. HDU4289 Control 最大流

    经典题,求去掉若干个点,使得两个点不在连通,总价值最少 所以拆点最小割,除了拆点边,流量都为无穷,拆点边是流量为价值 #include <iostream> #include <cs ...

  4. 自动化测试(二):QTP验证点

    1 程序自带验证点 自带验证点:图形界面insert  ->  checkpoint Standard Checkpoint 标准验证:用于检查测试对象的属性 Text Checkpoint 文 ...

  5. 依赖注入框架Autofac源码阅读指南

    官方网站http://autofac.org/ 源码下载地址https://github.com/autofac/Autofac 最新版本是3.5.0 下载后大小为37M,包括源码,示例文档,与之相关 ...

  6. 自己手动写http服务器(2)

    tringBuilder response =new StringBuilder(); //1) HTTP协议版本.状态代码.描述 response.append("HTTP/1.1&quo ...

  7. vim讲解

    文本编辑vi使用 最好使用vim,采用sudo apt-get install vim vi是Linux及类Unix系统中主流的命令行文本编辑器,功能极为强大,vim是增强版本的vim.Vim的高级地 ...

  8. 【Hadoop代码笔记】Hadoop作业提交之客户端作业提交

    1.      概要描述仅仅描述向Hadoop提交作业的第一步,即调用Jobclient的submitJob方法,向Hadoop提交作业. 2.      详细描述Jobclient使用内置的JobS ...

  9. HW6.25

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  10. 偶遇mysql外键不好使

    原来是创建表时选择的类型不一样,应该是innoDB,而且关联的主表类型也必须是innoDB