MyBatis整合第三方缓存框架EHCache

一、引入依赖
        <dependency>
            <groupId>org.mybatis.caches</groupId>
            <artifactId>mybatis-ehcache</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.5.3</version>
            <scope>test</scope>
        </dependency>
二、配置文件:固定名字ehcache.xml
<?xml version="1.0" encoding="UTF-8" ?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">
    <!--磁盘保存路径:缓存数据保存到磁盘上-->
    <diskStore path="D:\ehcache"></diskStore>
    <defaultCache
            maxElementsInMemory="1000"
            maxElementsOnDisk="10000000"
            eternal="false"
            overflowToDisk="true"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU">
    </defaultCache>
</ehcache>
三、SQL映射文件,设置cache标签type
 <cache type="org.mybatis.caches.ehcache.EhcacheCache">
四、创建logback.xml,名字是固定的
    由于存在slf4j时,简易日志log4j将失效,需要借助slf4j的具体实现logback来打印日志,创建logback的配置文件logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration debug="true">
    <!--日志输出位置-->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <!--日志输出格式-->
            <!--时间、日志级别、线程名字、打印日志的类、日志主体内容 换行-->
            <pattern>
                [%d{HH:mm:ss.SSS} [%-5level] [%thread] [%logger] [%msg]%n
            </pattern>
        </encoder>
    </appender>

    <!--設置全局日志級別-->
    <root level="DEBUG">
        <!--指定打印日志的appender-->
        <appender-ref ref="STDOUT"/>
    </root>

    <!--根据特殊需求,指定局部日志级别-->
    <logger name="com.java.ssm.mapper" level="DEBUG"></logger>
</Configuration>
slf4j相当于提供接口,logback-classic相当于slf4j的一个实现类的jar
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值