ssm配置ehcache没有效果

Ta曰丿、她活 2018-06-07 04:55:27
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">
<diskStore path="D:/cache" />
<!-- <diskStore path="java.io.tmpdir" /> -->
<defaultCache eternal="false" maxElementsInMemory="100" overflowToDisk="true" />
<cache name="tokenCache" maxElementsInMemory="1000" eternal="true" timeToIdleSeconds = "7200" timeToLiveSeconds = "7200" overflowToDisk="true" diskPersistent="true"/>
<cache name="ticketCache" maxElementsInMemory="1000" eternal="true" timeToIdleSeconds = "7200" timeToLiveSeconds = "7200" overflowToDisk="true" diskPersistent="true"/>
</ehcache>

applicationContext.xml 代码:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-3.1.xsd">

<!-- 设置定时任务 -->
<task:annotation-driven/>

<context:component-scan base-package="com.zlw.*"/>

<!-- 缓存配置 -->
<!-- 启用缓存注解功能(请将其配置在Spring主配置文件中) -->
<cache:annotation-driven cache-manager="cacheManager"/>
<!-- 若只想使用Spring自身提供的缓存器,则注释掉下面的两个关于Ehcache配置的bean,并启用上面的SimpleCacheManager即可 -->
<!-- Spring提供的基于的Ehcache实现的缓存管理器 -->
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"/>
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory"/>
</bean>
...
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
...

java:

@Cacheable(value = "tokenCache")
public String getAccessToken() {
// TODO Auto-generated method stub
String accessToken = null;
// 如果存储在数据库的token没有过期,则用当前token,否则重新获取token并更新数据库的token
// accessToken = iWxJSSDKService.getAccessToken();

/*if (!"-1".equalsIgnoreCase(accessToken)) {
log.debug("存储token为:" + accessToken);
return accessToken;
}*/
return "获取到的token";
}

这个token一开始是存在数据库,感觉这样这样不好,于是改成了缓存的方式。。。,其他功能都是正常的,后来添加的这个缓存配置,可是就是不起作用!!! 启动项目正常,就是缓存不起效果,求大佬
...全文
769 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ta曰丿、她活 2018-06-12
  • 打赏
  • 举报
回复
首先肯定不是配置的问题、
Ta曰丿、她活 2018-06-10
  • 打赏
  • 举报
回复
哎,没人吗?
爱写Bug的麦洛 2018-06-07
  • 打赏
  • 举报
回复
看了半天,看不出来哪里有毛病...........

39,083

社区成员

发帖
与我相关
我的任务
社区描述
HTML5是构建Web内容的一种语言描述方式。HTML5是互联网的下一代标准,是构建以及呈现互联网内容的一种语言方式.被认为是互联网的核心技术之一。
社区管理员
  • HTML5社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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