沉睡森林@漂在北京

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

            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 王總兵 閱讀(1764) 評論(0)  編輯  收藏 所屬分類: Spring
          主站蜘蛛池模板: 江川县| 齐河县| 石景山区| 大邑县| 海伦市| 郴州市| 承德县| 元氏县| 珲春市| 鄱阳县| 太仓市| 苏尼特右旗| 岱山县| 古丈县| 嘉荫县| 永宁县| 平邑县| 萝北县| 辉南县| 丰顺县| 特克斯县| 冷水江市| 汽车| 永泰县| 西畴县| 晋州市| 凤台县| 南江县| 西安市| 屏东县| 历史| 关岭| 镇原县| 阿瓦提县| 甘肃省| 安塞县| 色达县| 芜湖市| 马公市| 高密市| 保定市|