【100分】【在线等】Spring+ibatis+ehcache MethodCacheInterceptor的invoke方法没有执行

Gueis Gueis 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
小弟最新做一个项目 需要使用到Spring+ibatis+ehcache 参照网上的资料自己写了一些配置 可惜MethodCacheInterceptor的invoke方法始终没有执行。想请各位高人指点迷津

这个是Tomcat启动log信息 其中MethodCacheInterceptor已经被初始化了

2013-10-29 10:17:24,179 INFO [org.springframework.cache.ehcache.EhCacheManagerFactoryBean] main org.springframework.cache.ehcache.EhCacheManagerFactoryBean.afterPropertiesSet(EhCacheManagerFactoryBean.java:100) - <Initializing EHCache CacheManager>
2013-10-29 10:17:26,693 INFO [net.sf.ehcache.util.UpdateChecker] net.sf.ehcache.CacheManager@7b7d8769 net.sf.ehcache.util.UpdateChecker.doCheck(UpdateChecker.java:98) - <New update(s) found: 2.6.5 [http://www.terracotta.org/confluence/display/release/Release+Notes+Ehcache+Core+2.6]. Please check http://ehcache.org for the latest version.>
2013-10-29 10:17:30,781 INFO [com.gaotime.datadictionary.utils.MethodCacheInterceptor] main com.gaotime.datadictionary.utils.MethodCacheInterceptor.afterPropertiesSet(MethodCacheInterceptor.java:30) - <[ name = lowFreCache status = STATUS_ALIVE eternal = false overflowToDisk = true maxEntriesLocalHeap = 100000 maxEntriesLocalDisk = 500000 memoryStoreEvictionPolicy = LFU timeToLiveSeconds = 28800 timeToIdleSeconds = 28800 diskPersistent = false diskExpiryThreadIntervalSeconds = 120 cacheEventListeners: net.sf.ehcache.statistics.LiveCacheStatisticsWrapper hitCount = 0 memoryStoreHitCount = 0 diskStoreHitCount = 0 missCountNotFound = 0 missCountExpired = 0 maxBytesLocalHeap = 0 overflowToOffHeap = false maxBytesLocalOffHeap = 0 maxBytesLocalDisk = 0 pinned = false ] A cache is required. Use setCache(Cache) to provide one.>


这个是ehcache文件

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true"
monitoring="autodetect">
<diskStore path="java.io.tmpdir/ehcache" />
<defaultCache maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="600"
timeToLiveSeconds="600"
overflowToDisk="true"
diskSpoolBufferSizeMB="30"
maxElementsOnDisk="50000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"/>

<!-- 8小时更新缓存 -->
<cache name="lowFreCache"
maxElementsInMemory="100000"
maxElementsOnDisk="500000"
eternal="false"
overflowToDisk="true"
diskPersistent="false"
diskSpoolBufferSizeMB="30"
timeToIdleSeconds="28800"
timeToLiveSeconds="28800"
memoryStoreEvictionPolicy="LFU" />
</ehcache>


这个是applicationContext-cache.xml配置ehcache

<?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:cache="http://www.springframework.org/schema/cache"
xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

<!-- cacheManager工厂类,指定ehcache.xml的位置 -->
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:configLocation="classpath:/cache/ehcache.xml" p:shared="true"/>

<!--声明cacheManager -->
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"
p:cacheManager-ref="cacheManagerFactory" />

<!-- 8小时更新缓存 -->
<bean id="lowFreCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="cacheManager" ref="cacheManagerFactory" />
<property name="cacheName" value="lowFreCache" />
</bean>
<bean id="lowFreMethodCacheInterceptor" class="com.gaotime.datadictionary.utils.MethodCacheInterceptor">
<property name="cache" ref="lowFreCache"/>
</bean>
<bean id="lowFreMethodCachePointCut" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice" ref="lowFreMethodCacheInterceptor" />
<property name="patterns">
<list> <value>com.gaotime.datadictionary.kernel.service.impl.DataDictionaryServiceImpl\.getTableStructureInfoMap</value>
</list>
</property>
</bean>
</beans>


这个是MethodCacheInterceptor类代码


import java.io.Serializable;

import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.InitializingBean;

/**
* <b>function:</b> 缓存方法拦截器代码
* @file MethodCacheInterceptor.java
* @project Ehcache
* @version 1.0
*/
public class MethodCacheInterceptor implements MethodInterceptor, InitializingBean {

private static final Logger log = Logger.getLogger(MethodCacheInterceptor.class);

private Cache cache;

public void setCache(Cache cache) {
this.cache = cache;
}

public void afterPropertiesSet() throws Exception {
log.info(cache + " A cache is required. Use setCache(Cache) to provide one.");
}

public Object invoke(MethodInvocation invocation) throws Throwable {
String targetName = invocation.getThis().getClass().getName();
String methodName = invocation.getMethod().getName();
Object[] arguments = invocation.getArguments();
Object result;

String cacheKey = getCacheKey(targetName, methodName, arguments);
Element element = null;
try{
synchronized (this) {
element = cache.get(cacheKey);
if (element == null) {
// log.info(cacheKey + " Added to the cache: " + cache.getName());
result = invocation.proceed();
element = new Element(cacheKey, (Serializable) result);
cache.put(element);
} else {
// log.info(cacheKey + " Use Cached: " + cache.getName());
}
}
}catch(Exception e){
e.printStackTrace();
log.error(e.getMessage());
}
return element.getValue();
}

/**
* <b>function:</b> 返回具体的方法全路径名称 参数
* @param targetName 全路径
* @param methodName 方法名称
* @param arguments 参数
* @return 完整方法名称
*/
private String getCacheKey(String targetName, String methodName, Object[] arguments) {
StringBuffer sb = new StringBuffer();
sb.append(targetName).append(".").append(methodName);
if ((arguments != null) && (arguments.length != 0)) {
for (int i = 0; i < arguments.length; i++) {
sb.append(".").append(arguments[i]);
}
}
return sb.toString();
}
}


这个是classpath信息

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="conf"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/ehcache-core-2.5.0.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/ehcache-web-2.0.4.jar"/>
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
</classpath>



这个是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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<context:annotation-config/>
<!-- ① :对 web 包中的所有类进行扫描,以完成 Bean 创建和自动依赖注入的功能 -->
<context:component-scan base-package="com.gaotime.datadictionary.web.controller" />
<!-- ② :启动 Spring MVC 的注解功能,完成请求和注解 POJO 的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>
<!-- ③ :对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
<!-- Controller层异常处理 -->
<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="defaultErrorView">
<value>error/error</value>
</property>
</bean>
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
<import resource="spring/applicationContext-cache.xml"/>
</beans>
...全文

相关推荐

STM32F4 彩屏显示入门实验,含屏幕驱动和例程,新手可照着跑

这是我整理的 STM32F4 入门实验工程。里面有 TFT 彩屏显示驱动,还配了面包板上的 LED、按键这些基础外设,接线图也写了。刚开始学单片机的同学照着接就能亮屏,不用到处找例程。代码注释比较全,改参数就能换成自己的项目

2601_97255056

Delphi 13.2控件之DBX-0.6.26-x64-setup.exe.zip

Delphi 13.2控件之DBX_0.6.26_x64-setup.exe.zip

tjsoft

基于神经网络与ANFIS的自适应MPC车辆轨迹跟踪仿真研究(Matlab代码、Simulink仿真实现)

内容概要:本研究聚焦于基于神经网络与自适应神经模糊推理系统(ANFIS)优化的模型预测控制(MPC),实现对无人驾驶车辆轨迹的高精度跟踪。通过Matlab/Simulink搭建完整的车辆动力学模型与控制系统仿真环境,综合运用神经网络强大的非线性拟合能力与ANFIS的模糊逻辑推理优势,对传统MPC的预测模型或权重参数进行在线自适应调整,有效应对车辆系统在不同工况下的参数不确定性、外部干扰及强非线性问题。研究涵盖了从理论建模、算法设计到仿真验证的全过程,旨在提升MPC控制器在复杂动态环境下的鲁棒性和控制精度,确保车辆能够精确地沿预设轨迹(如双移线)行驶。; 适合人群:具备车辆动力学、自动控制原理和Matlab/Simulink仿真基础的研究生、科研人员及自动驾驶领域的算法工程师。; 使用场景及目标:① 研究和开发高级自动驾驶车辆的横向与纵向协同控制策略;② 解决传统MPC在面对模型失配和未知扰动时性能下降的问题,提升轨迹跟踪的鲁棒性;③ 为相关领域的学术研究(如硕士论文复现)和工程实践提供可复用的仿真代码和技术路线。; 阅读建议:学习者应重点关注神经网络与ANFIS是如何与MPC框架相结合的,理解其自适应机制的设计原理,并动手运行提供的Matlab代码和Simulink模型,通过调整参数和工况来观察控制效果的变化,从而深入掌握该复合控制策略的核心思想与实现细节。

三伯

地下矿井背包灭火器假人检测数据集VOC+YOLO格式2471张4类别.md

亲爱的CSDN用户: 首先感谢你点进这个资源页面。我需要提前说明一个重要情况: **本资源原本已设置为“0积分下载”**,即作者希望完全免费共享。但CSDN平台有时会根据文件的下载热度、文件大小、用户权限等因素,**自动将部分资源的积分调整为非0数值**(如1积分、2积分、5积分等)。这是平台系统的自动行为,而非作者本人的设定。 **因此,如果你当前看到该资源的下载所需积分不是0(例如显示为1、2、3……),请谨慎决定是否下载。** 如果你按照非0积分支付并下载后发现资源内容不符合预期、链接失效,或者实际上该资源本应是免费的,作者无法为此承担积分损失或退还操作。**强烈建议:仅在页面显示为0积分时进行下载。** 另外,本资源描述中**并未直接提供具体的下载地址或外部链接**,因为它本身是一个通过CSDN官方上传通道提交的文件/内容包。如果你看到描述中没有外部网盘地址,这是正常的——资源文件应通过CSDN内置的“下载”按钮获取。若因平台积分显示异常导致你支付了积分,请优先联系CSDN客服咨询积分退还政策,作者没有权限修改平台自动设定的积分值。 感谢你的理解与支持。技术分享本应开放,但受限于平台规则,特此提醒如上。祝学习进步!

fl176831

基于加速康复外科理念护理措施在腹腔镜胆囊切除术围手术期护理中的应用效果_唐晶晶.pdf

基于加速康复外科理念护理措施在腹腔镜胆囊切除术围手术期护理中的应用效果_唐晶晶.pdf

2601_97188640
评论 10
收藏 已收藏
分享
返回顶部
Gueis
Web 开发 81,108 成员 341,721 内容