沉睡森林@漂在北京

本处文章除注明“转载”外均为原创,转载请注明出处。

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  152 随笔 :: 4 文章 :: 114 评论 :: 0 Trackbacks
xml代码
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:cache
="http://www.springframework.org/schema/cache"  
    xmlns:p
="http://www.springframework.org/schema/p"  
    xsi:schemaLocation
="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
    http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"
>  
    <cache:annotation-driven />  
    <!-- generic cache manager -->  
    <bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">  
        <property name="caches">  
            <set>  
                <bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="default"/>  
                <bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="sys_resource"/>  
            </set>  
        </property>  
    </bean>  
</beans>  

java代码
package org.jeasyweb.framework.sys_user.service;

import java.util.Iterator;
import java.util.Set;

import org.jeasyweb.framework.sys_user.entity.SysResource;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;

@ContextConfiguration({ "classpath:applicationContext-dataSource.xml",
        "classpath:applicationContext-role.xml",
        "classpath:applicationContext-cache.xml" })
public class UserServiceTest extends
        AbstractTransactionalJUnit4SpringContextTests {
    @Autowired
    UserService userService;

    @Test
    public void testHello() {
        Set<SysResource> resources = userService
                .getResourceByUserId(new Long(1));
        Iterator<SysResource> it = resources.iterator();
    }

    @Test
    public void testCache() {
        Set<SysResource> resources2 = userService.getResourceByUserId(new Long(
                1));
    }
}

service代码
    @Override
    @Cacheable(value = "sys_resource", key = "'getResourceByUserId_' + #id")
    public Set<SysResource> getResourceByUserId(Long id) {
//.



posted on 2012-03-21 23:48 王总兵 阅读(1754) 评论(0)  编辑  收藏 所属分类: Spring

只有注册用户登录后才能发表评论。


网站导航: