springboot Ehcache使用
.Ehcache简单说明及使用 EhCache 是一个纯Java的进程内缓存框架,具有快速、精干等特点,是Hibernate中默认的CacheProvider。
Ehcache是一种广泛使用的开源Java分布式缓存。主要面向通用缓存,Java EE和轻量级容器。它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个gzip缓存servlet过滤器,支持REST和SOAP api等特点。
Ehcache最初是由Greg Luck于2003年开始开发。2009年,该项目被Terracotta购买。软件仍然是开源,但一些新的主要功能(例如,快速可重启性之间的一致性 的)只能在商业产品中使用,例如Enterprise EHCache and BigMemory。,维基媒体Foundationannounced目前使用的就是Ehcache技术。 Ehcache2.6.6 源码和jar包下载地址:https://oss.sonatype.org/content/repositories/sourceforge-releases/net/sf/ehcache/ehcache-core/2.6.6/ 2.1 添加依赖
```xml
<!-- 缓存 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!-- ehcache -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
``` 2.2 加入注解 @EnableCaching
```java
@SpringBootApplication
@EntityScan(basePackages ={ "entity","com.holworth.domain"})
@EnableCaching
public class domainApplication {}
```
2.3 EhCache配置
在src\main\resources目录下,添加ehcache.xml文件,
```xml
<?xml version="1.0" encoding="UTF-8" ?>
<ehcache>
<cache name="objectCache" maxElementsInMemory=""></cache>
</ehcache>
```
2.4 application.application配置
# 配置ehcache缓存
spring.cache.type=ehcache
# 指定ehcache配置文件路径
spring.cache.ehcache.config=classpath:/ehcache.xml 2.5
```java
package com.holworth.domain; import entity.BasCurrency;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cache.Cache;
import org.springframework.cache.annotation.EnableCaching;
import util.HraUtility;
import org.springframework.cache.CacheManager; import javax.annotation.Resource;
import java.util.List; @SpringBootApplication
@EntityScan(basePackages ={ "entity","com.holworth.domain"})
@EnableCaching
public class domainApplication {
@Resource
private CacheManager cacheManager;
// @Autowired
// private static com.holworth.domain.dao.a commonService; public static void main(String[] args) {
//http://localhost:8086/MKT/MktRiskPriceManage.html
//http://localhost:8080/api/RiskFactor/GetRiskFactor
SpringApplication.run(domainApplication.class);
CacheManager cacheManager = (CacheManager) SpringContextUtils.getBean("CacheManager");
Cache cache = cacheManager.getCache("objectCache");
cache.put("key", "");
System.out.println("缓存成功");
String res = cache.get("key", String.class);
System.out.println(res);
}
}
```
springboot Ehcache使用的更多相关文章
- springboot + ehcache
一.使用 springboot + ehcache本地堆缓存实现相应功能 1.引入ehcache的jar包 2.创建ehcache的xml配置文件 <?xml version="1.0 ...
- spring-boot + Ehcache without XML
http://stackoverflow.com/questions/21944202/using-ehcache-in-spring-4-without-xml 1.Ehcache配置类 @Conf ...
- springboot Ehcache缓存配置
例牌的导包 <!-- 包含支持UI模版(Velocity,FreeMarker,JasperReports), 邮件服务, 脚本服务(JRuby), 缓存Cache(EHCache), 任务计划 ...
- springboot+ehcache 基于注解实现简单缓存demo
1.加入maven依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...
- springboot(十九):SpringBoot+EHcache实现缓存
https://blog.csdn.net/qq_28143647/article/details/79789368
- spring boot学习(十三)SpringBoot缓存(EhCache 2.x 篇)
SpringBoot 缓存(EhCache 2.x 篇) SpringBoot 缓存 在 Spring Boot中,通过@EnableCaching注解自动化配置合适的缓存管理器(CacheManag ...
- Spring Boot集成EHCache实现缓存机制
SpringBoot 缓存(EhCache 2.x 篇) SpringBoot 缓存 在 Spring Boot中,通过@EnableCaching注解自动化配置合适的缓存管理器(CacheManag ...
- springboot+mybatis+ehcache实现缓存数据
一.springboot缓存简介 在 Spring Boot中,通过@EnableCaching注解自动化配置合适的缓存管理器(CacheManager),Spring Boot根据下面的顺序去侦测缓 ...
- SpringBoot整合Shiro使用Ehcache等缓存无效问题
前言 整合有缓存.事务的spring boot项目一切正常. 在该项目上整合shiro安全框架,发现部分类的缓存Cache不能正常使用. 然后发现该类的注解基本失效,包括事务Transaction注解 ...
随机推荐
- MySQL(基础技能)
一.概述 1.什么是数据库 ? 答:数据的仓库,如:在ATM的示例中我们创建了一个 db 目录,称其为数据库 2.什么是 MySQL.Oracle.SQLite.Access.MS SQL Serve ...
- junit,面向切面开发(动态代理),工厂设计模式,数据库连接池
1.junit junit又叫单元测试,好处是能进行批量测试,而且如果方法出现了问题能立刻定位出出现问题的方法,还有一个好处是感官效果很好,如果方法都通过了则显示绿条,否则显示红条 TestCase. ...
- Python module ---- os
os 模块Python标准库中的一个用于访问操作系统功能的模块,使用OS模块中提供的接口,可以实现跨平台访问.提供了一个统一的操作系统接口函数, 这些接口函数通常是平台指定的,os 模块能在不同操作系 ...
- 通过crt修改数据库中的存储过程
mysql -u idc_user -pidc_user123 通过crt修改数据库中的存储过程PRO_RET_HD_TZXW STEP1:在crt中查看数据库中的存储过程PRO_RET_HD_TZX ...
- Nginx配置跨域支持功能
跨域是前端开发中经常会遇到的问题,前端调用后台服务时,通常会遇到 No 'Access-Control-Allow-Origin' header is present on the requested ...
- spring AOP capbilities and goal
Spring AOP 是用纯JAVA 实现的. 不需借助JAVA代码在编译处理阶段来实现. Spring 是在运行期实现的.AOP的实现可以在编译,加载,运行三个阶段来实现:Spring AOP 也不 ...
- 安装软件,遇到弹框Windows Installer Coordinator,一直循环卡在这个弹框处
转载自https://www.cliftonsystems.co.uk/fixing-windows-installer-coordinator-loop/ 复制粘贴原文内容,以防将来访问不到原网页了 ...
- Game Engine Architecture 9
[Game Engine Architecture 9] 1.Formatted Output with OutputDebugString() int VDebugPrintF(const char ...
- 《Orange‘s》Loader
Loader 作用 引导扇区只有512个字节,能做的事情很少,局限性太大.所以需要一个程序,通过引导扇区加载入内存,然后将控制权交给它,这样就突破了512字节的限制.这个程序便是loader. 加载过 ...
- ucore-lab1-练习6report
练习6--完善中断初始化和处理 1. 中断向量表中一个表项占多少个字节?其中哪几位代表中断处理代码的入口? 答:系统将所有的中断事件统一进行编号(0-255),这个编号称为中断向量.中断向量表的一个 ...