spring MVC与Ehcache整合

分享一下我整合spring MVC与Ehcache遇到的问题:

1 下面这段配置是必须的了,但是如果单独写在一个xml文件中,并能被spring加载,却不能生效,但是如果写在spirng MVC的配置文件中就能够起作用

<!--  缓存  属性-->

    <bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">  
        <property name="configLocation"  value="classpath:config/ehcache.xml"/> 
</bean> 

<!-- 支持缓存注解 -->
    <cache:annotation-driven cache-manager="cacheManager" />
    
    <!-- 默认是cacheManager -->
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">  
        <property name="cacheManager"  ref="cacheManagerFactory"/>  

    </bean>

2 本人比较笨,还遇到下面的问题,问题虽然解决了但是不知道是怎么回事。

package com.fsj.spring.base.se;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import sinonet.framework.service.GenericCrudService;

import com.fsj.util.JsonUtils;
import com.nxy.domain.common.Syresourcetype;


@Controller
@RequestMapping("/base")
public class ResourceTypeController {
	@Autowired
	private UserService userService;
	
	@Autowired
	private GenericCrudService genericCrudService;
	
	@RequestMapping ("/doNotNeedSecurity_combobox")
	@Cacheable(value = "serviceCache")
	public List<Syresourcetype> doNotNeedSecurity_combobox()
	{
		return userService.getSyresourcetypeList();
//		return getSyresourcetypeList();
	}
	
//	@Cacheable(value = "serviceCache")
	public List<Syresourcetype> getSyresourcetypeList(){
		System.out.println("doNotNeedSecurity_combobox 非缓存查询");
		List<Syresourcetype> syresourcetypeList = (List<Syresourcetype>) genericCrudService.hql("select distinct t from  Syresourcetype t");
		return syresourcetypeList;
	}

}

public void doNotNeedSecurity_combobox(HttpServletRequest request,HttpServletResponse response)
	{
		new JsonUtils().writeJson(request, response, getSyresourcetypeList());
	}
两段代码相比,虽然只差了请求参数不一样,但是导致的结果也不一样,上面的代码除了第一次外,每次都能从缓存中查找到,而用下面的方法,就会不是100%从缓存中获取到,

很疑惑,希望有人能给指指道,小老弟不胜感激。。。

最近整理了学习材料,有需要的请下载,我放微信里面了,方便下载,还能交流,扫描我的二维码头像即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值