springmvc+mybatis+ehcahe配置了单独的ehcache.xml但还是一直使用默认的ehcache-failsafe.xml的配置

qq_35572020 2017-03-09 11:42:45
1.我使用的框架是srpingmvc+mybatis,然后想使用ehcache做二级缓存。

2.在网上找了很多方法,使用的方法如下:

(1)首先在springmvc.xml配置了
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:com/ssm/web/config/spring/ehcache.xml"/>
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory"/>
</bean>
(2)ehcache.xml配置
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd" updateCheck="false">
<diskStore path="F:\\ehcache"/>
<defaultCache
maxElementsInMemory="10"
maxElementsOnDisk="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="300"
overflowToDisk="true"
diskPersistent="true"
memoryStoreEvictionPolicy="LRU">
</defaultCache>
</ehcache>
(3)mapper.xml编写sql语句的地方加入
<!--mybatis ehcache缓存配置 -->
<!-- 以下两个<cache>标签二选一,第一个可以输出日志,第二个不输出日志 -->
<cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
<!--<cache type="org.mybatis.caches.ehcache.EhcacheCache"/> -->

做完以上的步骤就可以用了。
但有个问题是:我自己写的ehcache,xml的目录生成了,但是缓存的参数设置全部无效,全部使用的是ehcache-core.jar中的ehcache-failsefe.xml文件的配置,非常的奇怪,我自己设置的缓存有效时间是5分钟,默认的ehcache-failsefe.xml文件的配置是2分钟,实际测试时用的始终是默认的配置文件,但我自己设置的ehcache.xml的目录F盘有生成了一个文件夹,不过是一个空文件夹。

为什么会出现这样的问题呢?请大神们教教小弟,真的很不理解


...全文
799 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
别哔哔好伐 2018-10-26
  • 打赏
  • 举报
回复
引用 10 楼 qq_35572020 的回复:
[quote=引用 1 楼 pany1209 的回复:] 是因为找不到ehcache.xml才会使用ehcache-failsefe.xml。。。。
这里我稍微明白了一点,这个应该是springmvc+ehcache的配置,和mybatis好像无关。大神我这里还有一个问题: 今天想集成一个ehcache到mybatis做二级缓存,在网上搜索了很多资料(暂不涉及到springmvc框架)。 大体是这样做的: 1.首先要准备2个主要的jar包 ehcache-core-2.68.jar mybatis-ehcache-1.0.1.jar 2.在每一个编写sql语句的Mapper.xml下写上下面端代码 <!--mybatis ehcache缓存配置 --> <!-- 以下两个<cache>标签二选一,第一个可以输出日志,第二个不输出日志 --> <cache type="org.mybatis.caches.ehcache.LoggingEhcache"></cache> <!--<cache type="org.mybatis.caches.ehcache.EhcacheCache"/> --> 3.编写一个ehcache.xml <?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false"> <diskStore path="E:\\ehcache"/> <defaultCache maxElementsInMemory="10" maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" diskPersistent="true" memoryStoreEvictionPolicy="LRU"/> <cache name="userCache" maxElementsInMemory="10" maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" diskPersistent="true" memoryStoreEvictionPolicy="LRU" /> <cache name="CdCache" maxElementsInMemory="10" maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" diskPersistent="true" memoryStoreEvictionPolicy="LRU" /> </ehcache> 经过测试的确可以使用,但是有几个问题一直想不通,想请大神指点指点: 问题一:我测试的时候设置的清除缓存时间是一个小时,但是第一次查询的时候访问了sql语句,之后再2分钟以内访问是取缓存数据,但2分钟以后就会重新访问sql语句,也就是设置的清除缓存时间实际上只有2分钟,设置的参数无效。 问题二:设置的内存缓存最大是10条,超过后就缓存到E盘,但是E盘没有生成任何文件。 问题三:在ehcache.xml有很多个 带name名称的cache,这个怎么使用? 问题四:在测试的实际过程和网上的资料显示,我在ehcache-core-2.68.jar发现了一个ehcache-failsafe.xml文件,这个文件和我自己配置ehcache.xml几乎一样,就是设置的参数不一样,而且刚好ehcache-failsafe.xml文件设置的就是2分钟后就会清楚缓存,也就是说mybatis取的是jar包的文件,网上资料显示是没有找到ehcache.xml配置文件就会获取默认的jar包中的ehcache-failsafe.xml文件。而且我很疑惑,我编写的ehcache.xml在哪设置调取呢? 另外我的项目目录结构是这样的: 请大神指教指教,非常困惑,这里面没有用到springmvc框架,就纯粹使用mycatis+ehcache[/quote] 使用ehcache作为mybatis的二级缓存,mybatis-ehcache.jar 默认先找classpath路径下的ehcache.xml文件 ,找不到就去加载ehcache-core.jar下的ehcache-failsafe.xml文件。 你的ehcache.xml要放在classpath根目录下才会被找到。
danger_fate 2017-09-01
  • 打赏
  • 举报
回复
楼主,解决了吗? 小弟,遇到了同样的问题,不过是整合shiro的,系统总是加载shiro-ehcache-1.3.2.jar自带的ehcache.xml 若楼主已解决,希望能够回复,万分感谢!
andyLiuzy 2017-08-28
  • 打赏
  • 举报
回复
如果使用注解方式的话,还用不用在映射文件里加 <cache type="org.mybatis.caches.ehcache.LoggingEhcache"></cache>这句呢?
qq_35572020 2017-03-09
  • 打赏
  • 举报
回复
引用 3 楼 pany1209 的回复:
[quote=引用 2 楼 qq_35572020 的回复:] [quote=引用 1 楼 pany1209 的回复:] 是因为找不到ehcache.xml才会使用ehcache-failsefe.xml。。。。
这个我也知道,没有找到ehcache.xml才会使用ehcache-failsefe.xml,但我写了ehcache.xml,并且在springmvc.xml中引用了? 那要怎么样才能正确的找到呢?[/quote] 建议你在src下建个resources资源文件夹,再建个spring文件夹,把ehcache.xml放进去, 在spring的配置文件里配置

 <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
            <property name="configLocation" value="classpath:spring/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"/>
[/quote] 我是按照这样的目录来的,但是我加入<cache:annotation-driven cache-manager="cacheManager"/>这句话后会报一个小红叉“The prefix "cache" for element "cache:annotation-driven" is not bound.”;是少了什么网址没配置吗?
李德胜1995 2017-03-09
  • 打赏
  • 举报
回复
引用 2 楼 qq_35572020 的回复:
[quote=引用 1 楼 pany1209 的回复:] 是因为找不到ehcache.xml才会使用ehcache-failsefe.xml。。。。
这个我也知道,没有找到ehcache.xml才会使用ehcache-failsefe.xml,但我写了ehcache.xml,并且在springmvc.xml中引用了? 那要怎么样才能正确的找到呢?[/quote] 建议你在src下建个resources资源文件夹,再建个spring文件夹,把ehcache.xml放进去, 在spring的配置文件里配置

 <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
            <property name="configLocation" value="classpath:spring/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"/>
qq_35572020 2017-03-09
  • 打赏
  • 举报
回复
引用 1 楼 pany1209 的回复:
是因为找不到ehcache.xml才会使用ehcache-failsefe.xml。。。。
这个我也知道,没有找到ehcache.xml才会使用ehcache-failsefe.xml,但我写了ehcache.xml,并且在springmvc.xml中引用了? 那要怎么样才能正确的找到呢?
李德胜1995 2017-03-09
  • 打赏
  • 举报
回复
是因为找不到ehcache.xml才会使用ehcache-failsefe.xml。。。。
qq_35572020 2017-03-09
  • 打赏
  • 举报
回复
引用 1 楼 pany1209 的回复:
是因为找不到ehcache.xml才会使用ehcache-failsefe.xml。。。。
这里我稍微明白了一点,这个应该是springmvc+ehcache的配置,和mybatis好像无关。大神我这里还有一个问题: 今天想集成一个ehcache到mybatis做二级缓存,在网上搜索了很多资料(暂不涉及到springmvc框架)。 大体是这样做的: 1.首先要准备2个主要的jar包 ehcache-core-2.68.jar mybatis-ehcache-1.0.1.jar 2.在每一个编写sql语句的Mapper.xml下写上下面端代码 <!--mybatis ehcache缓存配置 --> <!-- 以下两个<cache>标签二选一,第一个可以输出日志,第二个不输出日志 --> <cache type="org.mybatis.caches.ehcache.LoggingEhcache"></cache> <!--<cache type="org.mybatis.caches.ehcache.EhcacheCache"/> --> 3.编写一个ehcache.xml <?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false"> <diskStore path="E:\\ehcache"/> <defaultCache maxElementsInMemory="10" maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" diskPersistent="true" memoryStoreEvictionPolicy="LRU"/> <cache name="userCache" maxElementsInMemory="10" maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" diskPersistent="true" memoryStoreEvictionPolicy="LRU" /> <cache name="CdCache" maxElementsInMemory="10" maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" diskPersistent="true" memoryStoreEvictionPolicy="LRU" /> </ehcache> 经过测试的确可以使用,但是有几个问题一直想不通,想请大神指点指点: 问题一:我测试的时候设置的清除缓存时间是一个小时,但是第一次查询的时候访问了sql语句,之后再2分钟以内访问是取缓存数据,但2分钟以后就会重新访问sql语句,也就是设置的清除缓存时间实际上只有2分钟,设置的参数无效。 问题二:设置的内存缓存最大是10条,超过后就缓存到E盘,但是E盘没有生成任何文件。 问题三:在ehcache.xml有很多个 带name名称的cache,这个怎么使用? 问题四:在测试的实际过程和网上的资料显示,我在ehcache-core-2.68.jar发现了一个ehcache-failsafe.xml文件,这个文件和我自己配置ehcache.xml几乎一样,就是设置的参数不一样,而且刚好ehcache-failsafe.xml文件设置的就是2分钟后就会清楚缓存,也就是说mybatis取的是jar包的文件,网上资料显示是没有找到ehcache.xml配置文件就会获取默认的jar包中的ehcache-failsafe.xml文件。而且我很疑惑,我编写的ehcache.xml在哪设置调取呢? 另外我的项目目录结构是这样的: 请大神指教指教,非常困惑,这里面没有用到springmvc框架,就纯粹使用mycatis+ehcache
李德胜1995 2017-03-09
  • 打赏
  • 举报
回复
引用 8 楼 qq_35572020 的回复:
[quote=引用 7 楼 pany1209 的回复:] [quote=引用 6 楼 qq_35572020 的回复:] [quote=引用 5 楼 pany1209 的回复:] [quote=引用 4 楼 qq_35572020 的回复:] [quote=引用 3 楼 pany1209 的回复:] [quote=引用 2 楼 qq_35572020 的回复:] [quote=引用 1 楼 pany1209 的回复:] 是因为找不到ehcache.xml才会使用ehcache-failsefe.xml。。。。
这个我也知道,没有找到ehcache.xml才会使用ehcache-failsefe.xml,但我写了ehcache.xml,并且在springmvc.xml中引用了? 那要怎么样才能正确的找到呢?[/quote] 建议你在src下建个resources资源文件夹,再建个spring文件夹,把ehcache.xml放进去, 在spring的配置文件里配置

 <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
            <property name="configLocation" value="classpath:spring/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"/>
[/quote] 我是按照这样的目录来的,但是我加入<cache:annotation-driven cache-manager="cacheManager"/>这句话后会报一个小红叉“The prefix "cache" for element "cache:annotation-driven" is not bound.”;是少了什么网址没配置吗?[/quote]在beans里面加上 xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation里面加上 http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd[/quote] 还是没有用;我把我整个项目贴出来你看一下吧,搞了一天了,还没搞定,拜托大神看看问题出在哪里吧。 项目路径: springmvc.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd"> <context:component-scan base-package="com.ssm.web.controller,com.ssm.app.controller"></context:component-scan> <mvc:annotation-driven conversion-service="conversionService1"></mvc:annotation-driven> <mvc:resources mapping="/static/**" location="/static/"/> <cache:annotation-driven cache-manager="cacheManager"/> <bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation" value="classpath:com/ssm/web/config/spring/ehcache.xml"/> </bean> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"> <property name="cacheManager" ref="cacheManagerFactory"/> </bean> </beans> 这个是我设置的ehcache.xml: <?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false"> <!--java.io.tmpdir 指的是你系统的缓存目录 --> <diskStore path="D:\\ehcache"/> <!-- name:Cache的唯一标识 maxElementsInMemory:内存中最大缓存对象数 maxElementsOnDisk:磁盘中最大缓存对象数,若是0表示无穷大 eternal:Element是否永久有效,一但设置了,timeout将不起作用 overflowToDisk:配置此属性,当内存中Element数量达到maxElementsInMemory时,Ehcache将会Element写到磁盘中 timeToIdleSeconds:设置Element在失效前的允许闲置时间(单位秒)。仅当element不是永久有效时使用,可选属性,默认值是0,也就是可闲置时间无穷大;缓存创建以后,最后一次访问缓存的日期至失效之时的时间间隔; timeToLiveSeconds:设置Element在失效前允许存活时间(单位秒)。最大时间介于创建时间和失效时间之 间。仅当element不是永久有效时使用,默认是0.,也就是element存活时间无穷大 ;缓存自创建日期起至失效时的间隔时间; diskPersistent:是否缓存虚拟机重启期数据 diskExpiryThreadIntervalSeconds:磁盘失效线程运行时间间隔,默认是120秒 diskSpoolBufferSizeMB:这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB。每个Cache都应该有自己的一个缓冲区 memoryStoreEvictionPolicy:当达到maxElementsInMemory限制时,Ehcache将会根据指定的策略去清理内存。默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用) 备注: 持久化到硬盘的路径由虚拟机参数"java.io.tmpdir"决定. 例如, 在windows中, 会在此路径下 C:\Documents and Settings\li\Local Settings\Temp 在linux中, 通常会在: /tmp 下 System.out.println(System.getProperty("java.io.tmpdir")); --> <defaultCache maxElementsInMemory="10" maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" diskPersistent="true" memoryStoreEvictionPolicy="LRU"> <!-- <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= true, replicateRemovals= true " /> --> </defaultCache> </ehcache> 这个是ehcache-core-2.4.6.jar的ehcache-failsafe.xml: <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd"> <diskStore path="java.io.tmpdir"/><defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" maxElementsOnDisk="10000000" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /> </ehcache> 这个是某一个的mapper.xml: ?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- 如果需要访问这条sql语,需要通过其唯一标识访问到 唯一标识就是 namespace+id的组合 --> <mapper namespace="com.ssm.web.mapper.AdminMapper"> <!--mybatis ehcache缓存配置 --> <!-- 以下两个<cache>标签二选一,第一个可以输出日志,第二个不输出日志 --> <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> <!--<cache type="org.mybatis.caches.ehcache.EhcacheCache"/> --> <resultMap id="BaseResultMap" type="com.ssm.web.entity.Admin"> <id column="id" property="id" jdbcType="VARCHAR" /> <result column="admin_code" property="admin_code" jdbcType="VARCHAR" /> <result column="admin_account" property="admin_account" jdbcType="VARCHAR" /> <result column="admin_name" property="admin_name" jdbcType="VARCHAR" /> <result column="admin_sex" property="admin_sex" jdbcType="VARCHAR" /> <result column="admin_password" property="admin_password" jdbcType="VARCHAR" /> <result column="admin_tel" property="admin_tel" jdbcType="VARCHAR" /> <result column="admin_registration_time" property="admin_registration_time" jdbcType="TIMESTAMP" /> </resultMap> <!--登录查询--> <select id="queryAll" parameterType="Admin" resultType="Admin"> select * from j_admin where admin_account=#{admin_account} and admin_password=#{admin_password} </select> </mapper> 运行结果: 在D盘生成了一个目录: 这里有几点很奇怪 <如果找到我自己配置的ehcache.xml,那为什么会生成一个目录呢?默认的目录是在C盘> <我设置的缓存内存为5,超过了的存入缓存,但缓存文件还是0kb> 然后我在控制台查看sql语句,我设置的是一个小时清楚缓存,在第一次查询后的2分钟内读取的是缓存,2分钟后就又重新查询了sql语句,这里我就证明它用的是jar的配置。 按照你给的方法,测试结果还是一样。[/quote]

<cache:annotation-driven cache-manager="cacheManager"/>
    <bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:com/ssm/web/config/spring/ehcache.xml"/>
    </bean>
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
        <property name="cacheManager" ref="cacheManagerFactory"/>
    </bean>
上面这段写在applicationContext-dao.xml里面试试[/quote] 还是没有用[/quote]在Mapper文件里加入

<cache type="org.mybatis.caches.ehcache.EhcacheCache"/>
还有pom文件加入依赖
<dependency>
		    <groupId>org.mybatis.caches</groupId>
		    <artifactId>mybatis-ehcache</artifactId>
		    <version>1.1.0</version>
		</dependency>
就可以了。。帮你试过了
qq_35572020 2017-03-09
  • 打赏
  • 举报
回复
引用 7 楼 pany1209 的回复:
[quote=引用 6 楼 qq_35572020 的回复:] [quote=引用 5 楼 pany1209 的回复:] [quote=引用 4 楼 qq_35572020 的回复:] [quote=引用 3 楼 pany1209 的回复:] [quote=引用 2 楼 qq_35572020 的回复:] [quote=引用 1 楼 pany1209 的回复:] 是因为找不到ehcache.xml才会使用ehcache-failsefe.xml。。。。
这个我也知道,没有找到ehcache.xml才会使用ehcache-failsefe.xml,但我写了ehcache.xml,并且在springmvc.xml中引用了? 那要怎么样才能正确的找到呢?[/quote] 建议你在src下建个resources资源文件夹,再建个spring文件夹,把ehcache.xml放进去, 在spring的配置文件里配置

 <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
            <property name="configLocation" value="classpath:spring/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"/>
[/quote] 我是按照这样的目录来的,但是我加入<cache:annotation-driven cache-manager="cacheManager"/>这句话后会报一个小红叉“The prefix "cache" for element "cache:annotation-driven" is not bound.”;是少了什么网址没配置吗?[/quote]在beans里面加上 xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation里面加上 http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd[/quote] 还是没有用;我把我整个项目贴出来你看一下吧,搞了一天了,还没搞定,拜托大神看看问题出在哪里吧。 项目路径: springmvc.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd"> <context:component-scan base-package="com.ssm.web.controller,com.ssm.app.controller"></context:component-scan> <mvc:annotation-driven conversion-service="conversionService1"></mvc:annotation-driven> <mvc:resources mapping="/static/**" location="/static/"/> <cache:annotation-driven cache-manager="cacheManager"/> <bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation" value="classpath:com/ssm/web/config/spring/ehcache.xml"/> </bean> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"> <property name="cacheManager" ref="cacheManagerFactory"/> </bean> </beans> 这个是我设置的ehcache.xml: <?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false"> <!--java.io.tmpdir 指的是你系统的缓存目录 --> <diskStore path="D:\\ehcache"/> <!-- name:Cache的唯一标识 maxElementsInMemory:内存中最大缓存对象数 maxElementsOnDisk:磁盘中最大缓存对象数,若是0表示无穷大 eternal:Element是否永久有效,一但设置了,timeout将不起作用 overflowToDisk:配置此属性,当内存中Element数量达到maxElementsInMemory时,Ehcache将会Element写到磁盘中 timeToIdleSeconds:设置Element在失效前的允许闲置时间(单位秒)。仅当element不是永久有效时使用,可选属性,默认值是0,也就是可闲置时间无穷大;缓存创建以后,最后一次访问缓存的日期至失效之时的时间间隔; timeToLiveSeconds:设置Element在失效前允许存活时间(单位秒)。最大时间介于创建时间和失效时间之 间。仅当element不是永久有效时使用,默认是0.,也就是element存活时间无穷大 ;缓存自创建日期起至失效时的间隔时间; diskPersistent:是否缓存虚拟机重启期数据 diskExpiryThreadIntervalSeconds:磁盘失效线程运行时间间隔,默认是120秒 diskSpoolBufferSizeMB:这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB。每个Cache都应该有自己的一个缓冲区 memoryStoreEvictionPolicy:当达到maxElementsInMemory限制时,Ehcache将会根据指定的策略去清理内存。默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用) 备注: 持久化到硬盘的路径由虚拟机参数"java.io.tmpdir"决定. 例如, 在windows中, 会在此路径下 C:\Documents and Settings\li\Local Settings\Temp 在linux中, 通常会在: /tmp 下 System.out.println(System.getProperty("java.io.tmpdir")); --> <defaultCache maxElementsInMemory="10" maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" diskPersistent="true" memoryStoreEvictionPolicy="LRU"> <!-- <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= true, replicateRemovals= true " /> --> </defaultCache> </ehcache> 这个是ehcache-core-2.4.6.jar的ehcache-failsafe.xml: <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd"> <diskStore path="java.io.tmpdir"/><defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" maxElementsOnDisk="10000000" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /> </ehcache> 这个是某一个的mapper.xml: ?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- 如果需要访问这条sql语,需要通过其唯一标识访问到 唯一标识就是 namespace+id的组合 --> <mapper namespace="com.ssm.web.mapper.AdminMapper"> <!--mybatis ehcache缓存配置 --> <!-- 以下两个<cache>标签二选一,第一个可以输出日志,第二个不输出日志 --> <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> <!--<cache type="org.mybatis.caches.ehcache.EhcacheCache"/> --> <resultMap id="BaseResultMap" type="com.ssm.web.entity.Admin"> <id column="id" property="id" jdbcType="VARCHAR" /> <result column="admin_code" property="admin_code" jdbcType="VARCHAR" /> <result column="admin_account" property="admin_account" jdbcType="VARCHAR" /> <result column="admin_name" property="admin_name" jdbcType="VARCHAR" /> <result column="admin_sex" property="admin_sex" jdbcType="VARCHAR" /> <result column="admin_password" property="admin_password" jdbcType="VARCHAR" /> <result column="admin_tel" property="admin_tel" jdbcType="VARCHAR" /> <result column="admin_registration_time" property="admin_registration_time" jdbcType="TIMESTAMP" /> </resultMap> <!--登录查询--> <select id="queryAll" parameterType="Admin" resultType="Admin"> select * from j_admin where admin_account=#{admin_account} and admin_password=#{admin_password} </select> </mapper> 运行结果: 在D盘生成了一个目录: 这里有几点很奇怪 <如果找到我自己配置的ehcache.xml,那为什么会生成一个目录呢?默认的目录是在C盘> <我设置的缓存内存为5,超过了的存入缓存,但缓存文件还是0kb> 然后我在控制台查看sql语句,我设置的是一个小时清楚缓存,在第一次查询后的2分钟内读取的是缓存,2分钟后就又重新查询了sql语句,这里我就证明它用的是jar的配置。 按照你给的方法,测试结果还是一样。[/quote]

<cache:annotation-driven cache-manager="cacheManager"/>
    <bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:com/ssm/web/config/spring/ehcache.xml"/>
    </bean>
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
        <property name="cacheManager" ref="cacheManagerFactory"/>
    </bean>
上面这段写在applicationContext-dao.xml里面试试[/quote] 还是没有用
李德胜1995 2017-03-09
  • 打赏
  • 举报
回复
引用 6 楼 qq_35572020 的回复:
[quote=引用 5 楼 pany1209 的回复:] [quote=引用 4 楼 qq_35572020 的回复:] [quote=引用 3 楼 pany1209 的回复:] [quote=引用 2 楼 qq_35572020 的回复:] [quote=引用 1 楼 pany1209 的回复:] 是因为找不到ehcache.xml才会使用ehcache-failsefe.xml。。。。
这个我也知道,没有找到ehcache.xml才会使用ehcache-failsefe.xml,但我写了ehcache.xml,并且在springmvc.xml中引用了? 那要怎么样才能正确的找到呢?[/quote] 建议你在src下建个resources资源文件夹,再建个spring文件夹,把ehcache.xml放进去, 在spring的配置文件里配置

 <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
            <property name="configLocation" value="classpath:spring/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"/>
[/quote] 我是按照这样的目录来的,但是我加入<cache:annotation-driven cache-manager="cacheManager"/>这句话后会报一个小红叉“The prefix "cache" for element "cache:annotation-driven" is not bound.”;是少了什么网址没配置吗?[/quote]在beans里面加上 xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation里面加上 http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd[/quote] 还是没有用;我把我整个项目贴出来你看一下吧,搞了一天了,还没搞定,拜托大神看看问题出在哪里吧。 项目路径: springmvc.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd"> <context:component-scan base-package="com.ssm.web.controller,com.ssm.app.controller"></context:component-scan> <mvc:annotation-driven conversion-service="conversionService1"></mvc:annotation-driven> <mvc:resources mapping="/static/**" location="/static/"/> <cache:annotation-driven cache-manager="cacheManager"/> <bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation" value="classpath:com/ssm/web/config/spring/ehcache.xml"/> </bean> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"> <property name="cacheManager" ref="cacheManagerFactory"/> </bean> </beans> 这个是我设置的ehcache.xml: <?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false"> <!--java.io.tmpdir 指的是你系统的缓存目录 --> <diskStore path="D:\\ehcache"/> <!-- name:Cache的唯一标识 maxElementsInMemory:内存中最大缓存对象数 maxElementsOnDisk:磁盘中最大缓存对象数,若是0表示无穷大 eternal:Element是否永久有效,一但设置了,timeout将不起作用 overflowToDisk:配置此属性,当内存中Element数量达到maxElementsInMemory时,Ehcache将会Element写到磁盘中 timeToIdleSeconds:设置Element在失效前的允许闲置时间(单位秒)。仅当element不是永久有效时使用,可选属性,默认值是0,也就是可闲置时间无穷大;缓存创建以后,最后一次访问缓存的日期至失效之时的时间间隔; timeToLiveSeconds:设置Element在失效前允许存活时间(单位秒)。最大时间介于创建时间和失效时间之 间。仅当element不是永久有效时使用,默认是0.,也就是element存活时间无穷大 ;缓存自创建日期起至失效时的间隔时间; diskPersistent:是否缓存虚拟机重启期数据 diskExpiryThreadIntervalSeconds:磁盘失效线程运行时间间隔,默认是120秒 diskSpoolBufferSizeMB:这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB。每个Cache都应该有自己的一个缓冲区 memoryStoreEvictionPolicy:当达到maxElementsInMemory限制时,Ehcache将会根据指定的策略去清理内存。默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用) 备注: 持久化到硬盘的路径由虚拟机参数"java.io.tmpdir"决定. 例如, 在windows中, 会在此路径下 C:\Documents and Settings\li\Local Settings\Temp 在linux中, 通常会在: /tmp 下 System.out.println(System.getProperty("java.io.tmpdir")); --> <defaultCache maxElementsInMemory="10" maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" diskPersistent="true" memoryStoreEvictionPolicy="LRU"> <!-- <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= true, replicateRemovals= true " /> --> </defaultCache> </ehcache> 这个是ehcache-core-2.4.6.jar的ehcache-failsafe.xml: <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd"> <diskStore path="java.io.tmpdir"/><defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" maxElementsOnDisk="10000000" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /> </ehcache> 这个是某一个的mapper.xml: ?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- 如果需要访问这条sql语,需要通过其唯一标识访问到 唯一标识就是 namespace+id的组合 --> <mapper namespace="com.ssm.web.mapper.AdminMapper"> <!--mybatis ehcache缓存配置 --> <!-- 以下两个<cache>标签二选一,第一个可以输出日志,第二个不输出日志 --> <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> <!--<cache type="org.mybatis.caches.ehcache.EhcacheCache"/> --> <resultMap id="BaseResultMap" type="com.ssm.web.entity.Admin"> <id column="id" property="id" jdbcType="VARCHAR" /> <result column="admin_code" property="admin_code" jdbcType="VARCHAR" /> <result column="admin_account" property="admin_account" jdbcType="VARCHAR" /> <result column="admin_name" property="admin_name" jdbcType="VARCHAR" /> <result column="admin_sex" property="admin_sex" jdbcType="VARCHAR" /> <result column="admin_password" property="admin_password" jdbcType="VARCHAR" /> <result column="admin_tel" property="admin_tel" jdbcType="VARCHAR" /> <result column="admin_registration_time" property="admin_registration_time" jdbcType="TIMESTAMP" /> </resultMap> <!--登录查询--> <select id="queryAll" parameterType="Admin" resultType="Admin"> select * from j_admin where admin_account=#{admin_account} and admin_password=#{admin_password} </select> </mapper> 运行结果: 在D盘生成了一个目录: 这里有几点很奇怪 <如果找到我自己配置的ehcache.xml,那为什么会生成一个目录呢?默认的目录是在C盘> <我设置的缓存内存为5,超过了的存入缓存,但缓存文件还是0kb> 然后我在控制台查看sql语句,我设置的是一个小时清楚缓存,在第一次查询后的2分钟内读取的是缓存,2分钟后就又重新查询了sql语句,这里我就证明它用的是jar的配置。 按照你给的方法,测试结果还是一样。[/quote]

<cache:annotation-driven cache-manager="cacheManager"/>
    <bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:com/ssm/web/config/spring/ehcache.xml"/>
    </bean>
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
        <property name="cacheManager" ref="cacheManagerFactory"/>
    </bean>
上面这段写在applicationContext-dao.xml里面试试
qq_35572020 2017-03-09
  • 打赏
  • 举报
回复
引用 5 楼 pany1209 的回复:
[quote=引用 4 楼 qq_35572020 的回复:]
[quote=引用 3 楼 pany1209 的回复:]
[quote=引用 2 楼 qq_35572020 的回复:]
[quote=引用 1 楼 pany1209 的回复:]
是因为找不到ehcache.xml才会使用ehcache-failsefe.xml。。。。

这个我也知道,没有找到ehcache.xml才会使用ehcache-failsefe.xml,但我写了ehcache.xml,并且在springmvc.xml中引用了? 那要怎么样才能正确的找到呢?[/quote]
建议你在src下建个resources资源文件夹,再建个spring文件夹,把ehcache.xml放进去,
在spring的配置文件里配置

<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:spring/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"/>
[/quote]

我是按照这样的目录来的,但是我加入<cache:annotation-driven cache-manager="cacheManager"/>这句话后会报一个小红叉“The prefix "cache" for element "cache:annotation-driven" is not bound.”;是少了什么网址没配置吗?[/quote]在beans里面加上
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation里面加上
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-3.1.xsd[/quote]

还是没有用;我把我整个项目贴出来你看一下吧,搞了一天了,还没搞定,拜托大神看看问题出在哪里吧。

项目路径:


springmvc.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-3.1.xsd">
<context:component-scan base-package="com.ssm.web.controller,com.ssm.app.controller"></context:component-scan>
<mvc:annotation-driven conversion-service="conversionService1"></mvc:annotation-driven>
<mvc:resources mapping="/static/**" location="/static/"/>
<cache:annotation-driven cache-manager="cacheManager"/>
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:com/ssm/web/config/spring/ehcache.xml"/>
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory"/>
</bean>
</beans>

这个是我设置的ehcache.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false">

<!--java.io.tmpdir 指的是你系统的缓存目录 -->
<diskStore path="D:\\ehcache"/>
<!--
name:Cache的唯一标识
maxElementsInMemory:内存中最大缓存对象数
maxElementsOnDisk:磁盘中最大缓存对象数,若是0表示无穷大
eternal:Element是否永久有效,一但设置了,timeout将不起作用
overflowToDisk:配置此属性,当内存中Element数量达到maxElementsInMemory时,Ehcache将会Element写到磁盘中
timeToIdleSeconds:设置Element在失效前的允许闲置时间(单位秒)。仅当element不是永久有效时使用,可选属性,默认值是0,也就是可闲置时间无穷大;缓存创建以后,最后一次访问缓存的日期至失效之时的时间间隔;
timeToLiveSeconds:设置Element在失效前允许存活时间(单位秒)。最大时间介于创建时间和失效时间之 间。仅当element不是永久有效时使用,默认是0.,也就是element存活时间无穷大 ;缓存自创建日期起至失效时的间隔时间;
diskPersistent:是否缓存虚拟机重启期数据
diskExpiryThreadIntervalSeconds:磁盘失效线程运行时间间隔,默认是120秒
diskSpoolBufferSizeMB:这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB。每个Cache都应该有自己的一个缓冲区
memoryStoreEvictionPolicy:当达到maxElementsInMemory限制时,Ehcache将会根据指定的策略去清理内存。默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用)
备注: 持久化到硬盘的路径由虚拟机参数"java.io.tmpdir"决定. 例如, 在windows中, 会在此路径下 C:\Documents and Settings\li\Local Settings\Temp 在linux中, 通常会在: /tmp 下 System.out.println(System.getProperty("java.io.tmpdir"));
-->
<defaultCache
maxElementsInMemory="10"
maxElementsOnDisk="10000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600"
overflowToDisk="true"
diskPersistent="true"
memoryStoreEvictionPolicy="LRU">
<!-- <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= true, replicateRemovals= true " /> -->
</defaultCache>
</ehcache>

这个是ehcache-core-2.4.6.jar的ehcache-failsafe.xml:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">
<diskStore path="java.io.tmpdir"/><defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
</ehcache>

这个是某一个的mapper.xml:
?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 如果需要访问这条sql语,需要通过其唯一标识访问到 唯一标识就是 namespace+id的组合 -->
<mapper namespace="com.ssm.web.mapper.AdminMapper">

<!--mybatis ehcache缓存配置 -->
<!-- 以下两个<cache>标签二选一,第一个可以输出日志,第二个不输出日志 -->
<cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
<!--<cache type="org.mybatis.caches.ehcache.EhcacheCache"/> -->

<resultMap id="BaseResultMap" type="com.ssm.web.entity.Admin">
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="admin_code" property="admin_code" jdbcType="VARCHAR" />
<result column="admin_account" property="admin_account" jdbcType="VARCHAR" />
<result column="admin_name" property="admin_name" jdbcType="VARCHAR" />
<result column="admin_sex" property="admin_sex" jdbcType="VARCHAR" />
<result column="admin_password" property="admin_password" jdbcType="VARCHAR" />
<result column="admin_tel" property="admin_tel" jdbcType="VARCHAR" />
<result column="admin_registration_time" property="admin_registration_time" jdbcType="TIMESTAMP" />
</resultMap>
<!--登录查询-->
<select id="queryAll" parameterType="Admin" resultType="Admin">
select * from j_admin where admin_account=#{admin_account} and admin_password=#{admin_password}
</select>
</mapper>


运行结果:
在D盘生成了一个目录:
这里有几点很奇怪
<如果找到我自己配置的ehcache.xml,那为什么会生成一个目录呢?默认的目录是在C盘>
<我设置的缓存内存为5,超过了的存入缓存,但缓存文件还是0kb>
然后我在控制台查看sql语句,我设置的是一个小时清楚缓存,在第一次查询后的2分钟内读取的是缓存,2分钟后就又重新查询了sql语句,这里我就证明它用的是jar的配置。

按照你给的方法,测试结果还是一样。
李德胜1995 2017-03-09
  • 打赏
  • 举报
回复
引用 4 楼 qq_35572020 的回复:
[quote=引用 3 楼 pany1209 的回复:] [quote=引用 2 楼 qq_35572020 的回复:] [quote=引用 1 楼 pany1209 的回复:] 是因为找不到ehcache.xml才会使用ehcache-failsefe.xml。。。。
这个我也知道,没有找到ehcache.xml才会使用ehcache-failsefe.xml,但我写了ehcache.xml,并且在springmvc.xml中引用了? 那要怎么样才能正确的找到呢?[/quote] 建议你在src下建个resources资源文件夹,再建个spring文件夹,把ehcache.xml放进去, 在spring的配置文件里配置

 <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
            <property name="configLocation" value="classpath:spring/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"/>
[/quote] 我是按照这样的目录来的,但是我加入<cache:annotation-driven cache-manager="cacheManager"/>这句话后会报一个小红叉“The prefix "cache" for element "cache:annotation-driven" is not bound.”;是少了什么网址没配置吗?[/quote]在beans里面加上 xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation里面加上 http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧