ehcache+springmvc 4.3 在使用@cacheable时出错
<!-- spring cache 配置 -->
<!-- 启用缓存注解功能,这个是必须的,否则注解不会生效,另外,该注解一定要声明在spring主配置文件中才会生效 -->
<cache:annotation-driven cache-manager="cacheManager"/>
<!-- 配置缓存管理器,获取cache -->
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehCacheFactory"/>
</bean>
<!-- 配置Ehcache缓存管理器,读取配置文件 -->
<bean id="ehCacheFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"/>
<property name="shared" value="true"/>
</bean>
我的SearchModel是一个实体,并且也实现了equal 、hashcode了;
方法传入方式如下:
leadsCombineChartsStatList(@ModelAttribute SearchModel searchModel, Integer start, Integer length)
{
// 其他code
leadsChartService.selectCombineEachDayLeads(searchModel);
// 其他code
}
不起作用的cacheable
@Cacheable(value = "leadsChartCache", key = "#searchModel.getBeginTime()+searchModel.getEndTime()", unless = "#searchModel==null")
@Override
public List<LeadsCombineChartViewModel> selectCombineEachDayLeads(SearchModel searchModel)
报错内容:
Property or field 'searchModel' cannot be found on object of type 'org.springframework.cache.interceptor.CacheExpressionRootObject' - maybe not public?
另外试了一下,改正这样的,也是报同样的错误:
@Cacheable(value = "leadsChartCache", key = "#root.targetClass+root.methodName")
<!-- 启用缓存注解功能,这个是必须的,否则注解不会生效,另外,该注解一定要声明在spring主配置文件中才会生效 -->
<cache:annotation-driven cache-manager="cacheManager"/>
<!-- 配置缓存管理器,获取cache -->
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehCacheFactory"/>
</bean>
<!-- 配置Ehcache缓存管理器,读取配置文件 -->
<bean id="ehCacheFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml"/>
<property name="shared" value="true"/>
</bean>
我的SearchModel是一个实体,并且也实现了equal 、hashcode了;
方法传入方式如下:
leadsCombineChartsStatList(@ModelAttribute SearchModel searchModel, Integer start, Integer length)
{
// 其他code
leadsChartService.selectCombineEachDayLeads(searchModel);
// 其他code
}
不起作用的cacheable
@Cacheable(value = "leadsChartCache", key = "#searchModel.getBeginTime()+searchModel.getEndTime()", unless = "#searchModel==null")
@Override
public List<LeadsCombineChartViewModel> selectCombineEachDayLeads(SearchModel searchModel)
报错内容:
Property or field 'searchModel' cannot be found on object of type 'org.springframework.cache.interceptor.CacheExpressionRootObject' - maybe not public?
另外试了一下,改正这样的,也是报同样的错误:
@Cacheable(value = "leadsChartCache", key = "#root.targetClass+root.methodName")
...全文
相关推荐
SpringMVC+Spring3+Hibernate4
SpringMVC+Spring3+Hibernate4开发环境搭建
SpringMVC+Mybatis+Spring+Shiro+ehcache整合配置文件
SpringMVC+Mybatis+Spring+Shiro+ehcache整合配置文件
springmvc4+spring4+hibernate5.1.3+二级缓存ehcache+fastjson配置
此配置和包,是springMVC4.3.3 +spring4+hibernate5.1.3+二级缓存ehcache(不用可以关闭)+fastjson。 是正常运行的项目里拷出来的,方便大家使用。
springmvc+ehcache 实例
maven +springmvc+ehcache实例 项目下载下来 直接运行 首页 有存储数据 获取数据 两个按钮 可以清晰看到ehcache作为缓存的效果
springmvc+ehcache简单例子
springmvc+ehcache简单例子,一看就懂


其他开发语言
