日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

Spring如何基于注解配置使用ehcache

瀏覽:109日期:2023-08-04 15:56:19

使用ehcache-spring-annotations使得在工程中簡單配置即可使用緩存

下載地址:http://code.google.com/p/ehcache-spring-annotations/

需要的jar包,首先需要的是我們之前做SpringMVC時的各個Spring的jar包

然后需要把ehcache-spring-annotations-1.2.0文件夾內lib內的,非spring的jar加進去,因為我們已經增加了我們版本的spring然后還需要動態代理的cglib包

在spring主配置文件中配置ehcache注解的使用:

<?xml version='1.0' encoding='UTF-8'?> <beans xmlns='http://www.springframework.org/schema/beans' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:mvc='http://www.springframework.org/schema/mvc' xmlns:p='http://www.springframework.org/schema/p' xmlns:context='http://www.springframework.org/schema/context' xmlns:aop='http://www.springframework.org/schema/aop' xmlns:tx='http://www.springframework.org/schema/tx' xmlns:ehcache='http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring' xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd'> <ehcache:annotation-driven cache-manager='ehCacheManager' /> <bean class='org.springframework.cache.ehcache.EhCacheManagerFactoryBean'> <property name='configLocation' value='classpath:ehcache.xml'/> </bean> <bean class='test.CacheService'></bean> </beans>

配置緩存配置文件ehcache.xml,改文件放在SRC下:

<?xml version='1.0' encoding='UTF-8'?> <ehcache xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='http://ehcache.org/ehcache.xsd' updateCheck='false'> <diskStore path='java.io.tmpdir' /> <defaultCache eternal='false' maxElementsInMemory='1000' overflowToDisk='false' diskPersistent='false' timeToIdleSeconds='0' timeToLiveSeconds='600' memoryStoreEvictionPolicy='LRU' /> <cache name='testCache' eternal='false' maxElementsInMemory='100' overflowToDisk='false' diskPersistent='false' timeToIdleSeconds='0' timeToLiveSeconds='300' memoryStoreEvictionPolicy='LRU' /> </ehcache>

CacheService是示例類,代碼如下:

package test; import java.util.Date; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.googlecode.ehcache.annotations.Cacheable; import com.googlecode.ehcache.annotations.TriggersRemove; public class CacheService{ @SuppressWarnings('deprecation') @Cacheable(cacheName = 'testCache') public String getName(String code){ System.out.println('查詢編號:' + code); return new Date().toLocaleString() + '-->' + code; } @SuppressWarnings('deprecation') @Transactional(propagation = Propagation.REQUIRED) public String update(String code){ System.out.println('更新編號:' + code); return new Date().toLocaleString() + '-->' + code; } @TriggersRemove(cacheName='testCache',removeAll=true) public void flush(){ System.out.println('情況緩存'); System.out.println('Processing testFlushing'); } }

改類包含根據參數獲取緩存值,更新緩存,情況緩存,都是使用注解標簽實現。

Action類需要改動一下,代碼如下:

package test; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; // http://localhost:8080/spring/hello.do?key=1&code=java @org.springframework.stereotype.Controller public class HelloController{ private CacheService sacheService; @SuppressWarnings('deprecation') @RequestMapping('/hello.do') public String hello(HttpServletRequest request,HttpServletResponse response){ String key = request.getParameter('key'); if('1'.equals(key)){ request.setAttribute('message', sacheService.getName(request.getParameter('code'))); }else if('2'.equals(key)){ request.setAttribute('message', sacheService.update(request.getParameter('code'))); }else{ sacheService.flush(); request.setAttribute('message', sacheService.getName(request.getParameter('code'))); } return 'hello'; } public CacheService getSacheService() { return sacheService; } @Autowired public void setSacheService(CacheService sacheService) { this.sacheService = sacheService; } }

根據key做不同的操作,然后分別訪問以下幾個路徑,為了方便看效果和學習,我把工程代碼放到了附件:

第一次沒有緩存http://localhost:8080/spring/hello.do?key=1&code=java讀取緩存http://localhost:8080/spring/hello.do?key=1&code=java更新緩存http://localhost:8080/spring/hello.do?key=2&code=java讀取最新緩存http://localhost:8080/spring/hello.do?key=1&code=java情況緩存http://localhost:8080/spring/hello.do?key=3

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
日韩av有码| 亚洲人成毛片在线播放女女| 日韩国产精品久久久| 天堂va蜜桃一区二区三区| 五月婷婷六月综合| 99成人在线| 亚洲欧美一级| 国产乱子精品一区二区在线观看 | 黄色亚洲免费| 欧美日韩国产一区精品一区| 亚洲手机视频| 一区在线视频观看| 欧美日韩视频一区二区三区| 欧美1级日本1级| 国产视频一区免费看| 在线视频亚洲| 蜜臀av性久久久久蜜臀aⅴ四虎| 老司机久久99久久精品播放免费| 最新亚洲国产| 国产精品igao视频网网址不卡日韩| 国产精品亚洲综合色区韩国| 久久超级碰碰| 欧洲一级精品| 在线国产一区| 亚洲一区二区三区高清不卡| 亚洲乱亚洲高清| 青青草伊人久久| 欧美国产日本| 成人午夜毛片| 欧美日韩中文一区二区| 热久久久久久久| 日本少妇一区二区| 成人精品视频| 国产精品日韩久久久| 日韩精品视频一区二区三区| 国产精品永久| 久久久久99| 亚洲欧美视频| 国产欧美激情| 91精品精品| 免费国产亚洲视频| 国产欧美一区二区三区米奇| 国产日韩电影| 五月综合激情| 日韩精选在线| 久久91导航| 久久成人一区| 欧美交a欧美精品喷水| 在线手机中文字幕| 羞羞答答国产精品www一本| 国产精品自在| 成人羞羞视频播放网站| 视频一区日韩| 亚洲天堂资源| 日韩中出av| 色偷偷色偷偷色偷偷在线视频| 蜜臀久久99精品久久久久久9 | 97精品国产福利一区二区三区| 国产一区二区中文| 亚洲欧洲免费| 精品资源在线| 玖玖精品视频| 国产成人久久精品麻豆二区| 9国产精品视频| 免费精品一区| 国产偷自视频区视频一区二区| 免费亚洲婷婷| 亚洲一区二区毛片| 亚洲综合电影| 91成人在线网站| 久久天堂av| 国产精品巨作av| 巨乳诱惑日韩免费av| 福利片在线一区二区| 亚洲色图网站| 在线一区视频观看| 欧美韩一区二区| 亚洲天堂日韩在线| 日韩精品麻豆| 国产欧美日本| 少妇高潮一区二区三区99| 久久国产欧美| 久久99精品久久久久久园产越南 | 中文字幕日韩亚洲| 色吊丝一区二区| 精品免费在线| 国产日韩欧美一区在线| 国产亚洲精品v| 欧美日韩精品免费观看视完整| 欧美黑人做爰爽爽爽| 日韩欧美高清一区二区三区| 欧美搞黄网站| 日韩影院二区| 成人亚洲精品| 国产精品美女在线观看直播| 蜜桃视频一区二区三区在线观看| 色综合www| 福利一区二区免费视频| 国产精品videossex| 日本aⅴ精品一区二区三区| 欧美专区18| 国产精品腿扒开做爽爽爽挤奶网站| 在线精品亚洲欧美日韩国产| 欧美激情视频一区二区三区免费 | 亚洲精品福利| 丝袜国产日韩另类美女| 亚洲性色av| 国产精品麻豆久久| 国产一区二区三区四区五区| 国产麻豆一区| 国产伦精品一区二区三区在线播放| 亚洲精品动态| 亚洲资源网站| 蜜臀va亚洲va欧美va天堂| 欧美天堂亚洲电影院在线观看| 国产综合激情| 午夜久久福利| 一区在线视频观看| 一本一本久久| 日韩中文字幕不卡| 综合在线一区| 亚洲欧美日韩专区| 亚洲天堂免费| 日韩高清一区| 国产乱码精品一区二区三区亚洲人| 欧美日韩1区2区3区| 日韩成人午夜精品| 欧美日韩一区二区三区不卡视频 | 免费观看不卡av| 日韩在线高清| 丝袜美腿诱惑一区二区三区| 丝袜美腿诱惑一区二区三区 | 性欧美精品高清| 丝袜亚洲精品中文字幕一区| 乱人伦精品视频在线观看| 老牛影视一区二区三区| 亚洲一二三区视频| 欧美在线不卡| 久久99精品久久久久久园产越南 | 日韩久久电影| 欧洲精品一区二区三区| 国产99久久久国产精品成人免费| 久久精品亚洲人成影院 | re久久精品视频| 中文亚洲免费| 日韩高清中文字幕一区| 国产精品激情| a天堂资源在线| 欧美日韩国产欧| 日韩激情视频网站| 久久久久伊人| 久久久久美女| 蜜臀av国产精品久久久久| 日韩精品一区二区三区av| 国产精品免费大片| 久久天堂av| 亚洲午夜久久| 九九九精品视频| 欧美亚洲国产精品久久| 亚洲一区二区三区四区电影 | 欧美日本不卡高清| 国产一区二区三区天码| 国产在线不卡| 天堂va欧美ⅴa亚洲va一国产| 免费在线成人| 伊人久久大香线蕉av不卡| 亚洲视频二区| 国内一区二区三区| 夜夜嗨一区二区| 国产精品免费大片| 欧美成人综合| 国产麻豆精品| 欧美日韩中文一区二区| 少妇精品久久久一区二区| 国产专区精品| 天使萌一区二区三区免费观看| 国产精品对白久久久久粗| 蜜桃伊人久久| 国产精品一国产精品| 成人精品国产亚洲| 欧美一级精品| 欧美啪啪一区| 久久免费高清| 欧美日韩一区二区三区在线电影| 日韩欧美网址| 日韩美女精品| 中文字幕系列一区| 日韩av一区二区在线影视| 日韩免费av| 青草国产精品久久久久久| 日韩av首页| 国产精品一区二区免费福利视频 | 国产精品videossex久久发布 | 国产精品极品| 一区久久精品| 国产一区二区三区日韩精品| 在线国产精品一区| 精精国产xxxx视频在线播放| 日韩不卡在线观看日韩不卡视频| 欧美成a人国产精品高清乱码在线观看片在线观看久 |