沉睡森林@漂在北京

          本處文章除注明“轉載”外均為原創,轉載請注明出處。

            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 王總兵 閱讀(1765) 評論(0)  編輯  收藏 所屬分類: Spring
          主站蜘蛛池模板: 邢台县| 依兰县| 汝阳县| 景宁| 博乐市| 桐柏县| 昌吉市| 汨罗市| 高雄市| 曲周县| 如东县| 张掖市| 息烽县| 特克斯县| 西城区| 灵丘县| 阿合奇县| 益阳市| 石台县| 南靖县| 健康| 遵义县| 阿尔山市| 九龙城区| 阳谷县| 密云县| 宝清县| 和田市| 尉氏县| 稻城县| 锡林浩特市| 江安县| 乌拉特前旗| 定日县| 呼玛县| 茌平县| 清新县| 札达县| 武山县| 临泽县| 台北县|