spring boot 配置Cache
来源:互联网 发布:股票行情软件哪家好 编辑:程序博客网 时间:2024/06/06 17:39
1.在pom文件中配置版本信息
<properties>
<jcache.version>1.0.0</jcache.version>
</properties>
并添加依赖包:
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jcache</artifactId>
<version>${hibernate.version}</version>
</dependency>
2.新建配置文件
ehache-dev.xml
<?xml version="1.0" encoding="UTF-8"?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns='http://www.ehcache.org/v3' xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd"> <cache-template name="simple"> <expiry> <ttl unit="seconds">3600</ttl> </expiry> <heap unit="entries">100000</heap> </cache-template> <cache alias="surveyQuestion" uses-template="simple"/> <cache alias="surveyOption" uses-template="simple"/> <cache alias="paper" uses-template="simple"/> <!-- jhipster-needle-ehcache-add-entry --></config>ehache-prod.xml
配置系统配置文件<?xml version="1.0" encoding="UTF-8"?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns='http://www.ehcache.org/v3' xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd"> <cache-template name="simple"> <expiry> <ttl unit="seconds">3600</ttl> </expiry> <heap unit="entries">100000</heap> </cache-template> <cache alias="surveyQuestion" uses-template="simple"/> <cache alias="surveyOption" uses-template="simple"/> <cache alias="paper" uses-template="simple"/> <!-- jhipster-needle-ehcache-add-entry --></config>
application-dev.yml
spring: profiles: active: dev include: swagger devtools: restart: enabled: true livereload: enabled: false # we use gulp + BrowserSync for livereload jackson: serialization.indent_output: true datasource: type: com.zaxxer.hikari.HikariDataSource url: jdbc:mysql://localhost:3306/survey?useUnicode=true&characterEncoding=utf8&useSSL=false username: root password: root hikari: data-source-properties: cachePrepStmts: true prepStmtCacheSize: 250 prepStmtCacheSqlLimit: 2048 useServerPrepStmts: true jpa: database-platform: org.hibernate.dialect.MySQL5InnoDBDialect database: MYSQL show-sql: true properties: hibernate.id.new_generator_mappings: true hibernate.cache.use_second_level_cache: false hibernate.cache.use_query_cache: true hibernate.generate_statistics: true hibernate.javax.cache.provider: org.ehcache.jsr107.EhcacheCachingProvider hibernate.javax.cache.uri: ${spring.cache.jcache.config} hibernate.cache.region.factory_class: io.github.jhipster.config.jcache.SpringCacheRegionFactory cache: jcache: config: config/ehcache/ehcache-dev.xmlapplication-prod.yml
spring: devtools: restart: enabled: false livereload: enabled: false datasource: type: com.zaxxer.hikari.HikariDataSource url: jdbc:mysql://10.0.101.156:3306/survey?useUnicode=true&characterEncoding=utf8&useSSL=false username: root password: hikari: data-source-properties: cachePrepStmts: true prepStmtCacheSize: 250 prepStmtCacheSqlLimit: 2048 useServerPrepStmts: true jpa: database-platform: org.hibernate.dialect.MySQL5InnoDBDialect database: MYSQL show-sql: false properties: hibernate.id.new_generator_mappings: true hibernate.cache.use_second_level_cache: false hibernate.cache.use_query_cache: true //需要打开 hibernate.generate_statistics: true //需要打开 hibernate.javax.cache.provider: org.ehcache.jsr107.EhcacheCachingProvider hibernate.javax.cache.uri: ${spring.cache.jcache.config} hibernate.cache.region.factory_class: io.github.jhipster.config.jcache.SpringCacheRegionFactory cache: //添加上cache的配置文件路径 jcache: config: config/ehcache/ehcache-prod.xml3.新建一个java配置文件
package com.qdum.survey.config;import org.springframework.boot.autoconfigure.AutoConfigureAfter;import org.springframework.boot.autoconfigure.AutoConfigureBefore;import org.springframework.cache.annotation.EnableCaching;import org.springframework.context.annotation.*;@Configuration@EnableCaching@AutoConfigureAfter(value = { MetricsConfiguration.class })@AutoConfigureBefore(value = { WebConfigurer.class, DatabaseConfiguration.class })public class CacheConfiguration {}
阅读全文
0 0
- Spring boot配置cache
- spring boot 配置Cache
- Spring boot配置cache(ehcache)
- Spring Boot集成cache
- #spring boot 3 -- cache
- spring-boot中配置和使用Caffeine Cache
- spring-boot中配置和使用Caffeine Cache
- Spring-boot中使用Cache
- Spring Boot 数据缓存 Cache
- spring boot cache理论详解
- Spring Boot+Spring Data JPA+Spring Cache
- spring boot spring cache ehcache3.x整合
- spring boot中spring cache 整合redis
- 36. Spring Boot Cache理论篇【从零开始学Spring Boot】
- 36. Spring Boot Cache理论篇【从零开始学Spring Boot】
- Spring Boot 菜鸟教程 17 Cache-缓存
- spring-boot配置文件-cache(中文翻译)
- Spring Boot 轻量级缓存 Ace-Cache
- 阿里云服务器上的乌版图下使用apt-get安装Mongodb数据库
- CSDN-markdown编辑器使用指南
- python 文件操作
- checkbox
- 2017年第二十五届中国(深圳)国际礼品及家居用品展览会会刊(参展商名录)
- spring boot 配置Cache
- cxf实现webservice
- MongoDB干货系列2-MongoDB执行计划分析详解(2)
- Errors occurred during the build. Errors running builder 'Integrated External Tool Builder' on proje
- JS回调函数--简单易懂有实例
- js中append函数引用函数的时候传参方法
- 推荐 | 10.24......送你9大深度学习在线课程,你没理由不看!(附链接......)
- hive mapjoin 使用
- Java中System.setProperty()用法