67,513
社区成员
发帖
与我相关
我的任务
分享
<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.”;是少了什么网址没配置吗?
<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"/>
<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>
就可以了。。帮你试过了
<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]
还是没有用
<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里面试试
<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]
<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