java 缓存ech_springBoot缓存技术-整合Ehcache

1 修改pom文件

20f31462ab1846ed75cf6d81c51ab990.png

2 创建Ehcache的配置文件

文件名:ehcache.xml

位置:src/main/resources/ehcache.xml

maxElementsInMemory="10000"

eternal="false"

timeToIdleSeconds="120"

timeToLiveSeconds="120"

maxElementsOnDisk="10000000"

diskExpiryThreadIntervalSeconds="120"

memoryStoreEvictionPolicy="LRU">

maxElementsInMemory="10000"

eternal="false"

timeToIdleSeconds="120"

timeToLiveSeconds="120"

maxElementsOnDisk="10000000"

diskExpiryThreadIntervalSeconds="120"

memoryStoreEvictionPolicy="LRU">

3 修改application.properties文件

spring.datasource.driverClassName=com.mysql.jdbc.Driver

spring.datasource.url=jdbc:mysql://localhost:3306/ssm

spring.datasource.username=root

spring.datasource.password=root

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource

spring.jpa.hibernate.ddl-auto=update

spring.jpa.show-sql=true

spring.cache.ehcache.cofnig=ehcache.xml

4 修改启动类

d8dbf4ed574308f84658e4d0665e63cf.png

5 创建业务层

6e7509aa20a0c700d5403d2ed799e478.png

6 修改实体类Users

d8453a6cdbc92531a5fd323122db251c.png

7 测试

/**

* UsersService测试

*

*

*/

@RunWith(SpringJUnit4ClassRunner.class)

@SpringBootTest(classes=App.class)

public class UsersServiceTest {

@Autowired

private UsersService usersService;

@Test

public void testFindUserById(){

//第一次查询

System.out.println(this.usersService.findUserById(1));

//第二次查询

System.out.println(this.usersService.findUserById(1));

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"C:\Program Files\Java\jdk-1.8\bin\java.exe" -Dmaven.multiModuleProjectDirectory=F:\workmode\h5xjxj\ech-log-server\ech-log-api -Djansi.passthrough=true -Dmaven.home=F:\dev_software\apache-maven-3.6.3 -Dclassworlds.conf=F:\dev_software\apache-maven-3.6.3\bin\m2.conf "-Dmaven.ext.class.path=F:\idea2023\IntelliJ IDEA 2023.1.2\plugins\maven\lib\maven-event-listener.jar" "-javaagent:F:\idea2023\IntelliJ IDEA 2023.1.2\lib\idea_rt.jar=53993:F:\idea2023\IntelliJ IDEA 2023.1.2\bin" -Dfile.encoding=UTF-8 -classpath F:\dev_software\apache-maven-3.6.3\boot\plexus-classworlds-2.6.0.jar;F:\dev_software\apache-maven-3.6.3\boot\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version=2023.1.2 -s C:\Users\田文成\.m2\settings_XJ_git.xml -Dmaven.repo.local=F:\dev_software\repository\localRepository\localRepository install [INFO] Scanning for projects... [INFO] [INFO] -----------------------< com.ai.ecs:ech-log-api >----------------------- [INFO] Building ech-log-api 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- Downloading from nexus1: http://mgr.devstone.cn:18080/nexus/content/groups/public/org/apache/maven/plugins/maven-compiler-plugin/2.5.1/maven-compiler-plugin-2.5.1.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 22.280 s [INFO] Finished at: 2023-07-12T16:30:43+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Plugin org.apache.maven.plugins:maven-compiler-plugin:2.5.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:2.5.1: Could not transfer artifact org.apache.maven.plugins:maven-compiler-plugin:pom:2.5.1 from/to nexus1 (http://mgr.devstone.cn:18080/nexus/content/groups/public): Transfer failed for http://mgr.devstone.cn:18080/nexus/content/groups/public/org/apache/maven/plugins/maven-compiler-plugin/2.5.1/maven-compiler-plugin-2.5.1.pom: Connect to mgr.devstone.cn:18080 [mgr.devstone.cn/218.94.91.233] failed: Connection timed out: connect -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException 刚导入项目依赖报错
07-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值