mybatis+ehcache走过的坑
来源:互联网 发布:用js写满天闪烁的星星 编辑:程序博客网 时间:2024/05/29 05:53
1:所需要的配置文件和需要配的东西如下
(1)maven
<!-- ehcache与mybatis整合 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-ehcache</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.0.0.m3</version>
</dependency>
注意:这里可能会有依赖冲突,ehcache里面有lsf4j-api 可能会跟其他东西冲突,遇到问题请自行解决依赖问题。
(2)spring 配置
<!-- 开启spring缓存 -->
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"></property>
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehcache"></property>
</bean>
<cache:annotation-driven cache-manager="cacheManager" />
一般配这里两个再加上复制来的ehcache.xml文件是没问题的,但是遇到过许多问题异常下面整理
2:异常展示
(1):Error creating bean with name 'ehcache' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Error configuring from input stream. Initial cause was Invalid byte 1 of 1-byte UTF-8 sequence.
这里关键是看最后面的东西,刚开始觉得很莫名其妙跟编码有什么关系,后面将ehcache.xml中文注释给删了才好,真是的注释都不能用中文。
(2):Error creating bean with name 'ehcache' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: net.sf.ehcache.CacheManager.create(Lnet/sf/ehcache/config/Configuration;)Lnet/sf/ehcache/CacheManager;
一般NoSuchMethodError都是因为没找到类跟导包有原因,而这里是因为加上了<property name="shared" value="true"></property> 这玩意,这里原因没具体研究大概就是有两个CacheManager的方法 我们可以用默认的 然后我们加了这句就是去另外个没导进来的里面去找了 ,目前关于ehcache+mybatis的整合出现的问题就这两种。
然后用法的话很简单:就是在mabaits dao的xml文件上面加上一 <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> 这个是有日志的那种 还有句是没有日志的,然后如果有的不想要缓存的话 在sql上面加上useCache="false"取消就好了。
- mybatis+ehcache走过的坑
- 设计走过的坑
- spilt走过的坑
- mybatis ehcache的一点小记
- 坑!自己走过的坑...
- c++11 走过的坑
- java 后台走过的坑
- Android-->我走过的坑
- Android Studio 走过的坑
- elasticsearch走过的一些坑
- eclipse 下载走过的坑
- 近日小结【走过的坑】
- 我所走过的坑
- 记录javaweb走过的坑
- ehcache作为Mybatis二级缓存的问题
- 走过的那些白痴的坑
- 走过的laravel-admin 的坑
- 记录Mybatis和Ehcache结合时启用延迟加载的一个坑
- 初识monkeyrunner
- Java方法
- 6数据库的连接
- 对不同激活函数在神经网络中的比较分析
- php 冒泡排序&快速排序
- mybatis+ehcache走过的坑
- LaTeX Error: Unknown graphics extension: .eps 处理
- laravel 5.4 composer 安装心的
- nova 热迁移卷 的关键代码 rebase说明
- 03:基因相关性(1.7编程基础之字符串)
- 图解JVM内存结构及内存/栈溢出原因解析
- TurboPixels: Fast Superpixels Using Geometric Flows
- 【转】Global.asax.cs中的方法(包括自定义方法)的含义
- Android快速开发系列 10个常用工具类