沉睡森林@漂在北京

          本處文章除注明“轉(zhuǎn)載”外均為原創(chuàng),轉(zhuǎn)載請(qǐng)注明出處。

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            152 隨筆 :: 4 文章 :: 114 評(píng)論 :: 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 王總兵 閱讀(1774) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Spring
          主站蜘蛛池模板: 灌南县| 临高县| 定结县| 江华| 奉贤区| 河源市| 苏尼特右旗| 兴安盟| 西丰县| 宜都市| 蓝田县| 平泉县| 庆云县| 丹东市| 犍为县| 紫金县| 信阳市| 石阡县| 博白县| 黎川县| 枝江市| 平阴县| 鞍山市| 弥勒县| 东兴市| 永春县| 镶黄旗| 错那县| 黑山县| 上林县| 吐鲁番市| 全州县| 天津市| 新干县| 澎湖县| 博客| 安陆市| 惠东县| 宜良县| 丰台区| 包头市|