当前位置: 首页 > news >正文

外贸平台自建站谷歌外链代发

外贸平台自建站,谷歌外链代发,网上创建公司,国际贸易app平台之前为大家介绍了如何使用spring注解来进行缓存配置 #xff08;EHCache 和 OSCache#xff09;的简单的例子#xff0c;详见 Spring基于注解的缓存配置--EHCache AND OSCache 现在介绍一下如何在基于注解springMVC的web应用中使用注解缓存#xff0c;其实很简单#xff0…之前为大家介绍了如何使用spring注解来进行缓存配置 EHCache 和 OSCache的简单的例子详见 Spring基于注解的缓存配置--EHCache AND OSCache 现在介绍一下如何在基于注解springMVC的web应用中使用注解缓存其实很简单就是将springMVC配置文件与缓存注解文件一起声明到context中就OK了。 下面我就来构建一个基于spring注解小型的web应用,这里我使用EHCache来作为缓存方案 jar依赖 ehcache-core-1.7.2.jar jakarta-oro-2.0.8.jar slf4j-api-1.5.8.jar slf4j-jdk14-1.5.8.jar cglib-nodep-2.1_3.jar commons-logging.jar log4j-1.2.15.jar spring-modules-cache.jar spring.jar jstl.jar standard.jar 接着我们来编写web.xml ?xml version1.0 encodingUTF-8? web-app xmlnshttp://java.sun.com/xml/ns/j2ee xmlns:xsihttp://www.w3.org/2001/XMLSchema-instanceidWebApp_ID version2.4xsi:schemaLocationhttp://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsddisplay-nameSpringCacheWeb/display-name!-- 由spring加载log4j --context-paramparam-namelog4jConfigLocation/param-nameparam-valueclasspath:log4j.properties/param-value/context-param!-- 声明spring配置文件 --context-paramparam-namecontextConfigLocation/param-nameparam-value/WEB-INF/spring-servlet.xml/param-value/context-param!-- 使用UTF-8编码 --filterfilter-nameSet Character Encoding/filter-namefilter-classorg.springframework.web.filter.CharacterEncodingFilter/filter-classinit-paramparam-nameencoding/param-nameparam-valueUTF-8/param-value/init-param/filterfilter-mappingfilter-nameSet Character Encoding/filter-nameurl-pattern*.do/url-pattern/filter-mapping!-- 负责初始化log4j--listenerlistener-classorg.springframework.web.util.Log4jConfigListener/listener-class/listener!-- 负责初始化spring上下文--listenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listener!-- springMVC控制器--servletservlet-namespring/servlet-nameservlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-classload-on-startup1/load-on-startup/servletservlet-mappingservlet-namespring/servlet-nameurl-pattern*.do/url-pattern/servlet-mappingsession-configsession-timeout10/session-timeout/session-configwelcome-file-listwelcome-fileindex.jsp/welcome-filewelcome-fileindex.html/welcome-filewelcome-fileindex.htm/welcome-file/welcome-file-list /web-app接着我们来编写spring-servlet.xml   ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:contexthttp://www.springframework.org/schema/contextxmlns:ehcachehttp://www.springmodules.org/schema/ehcachexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsddefault-lazy-inittrue!--启用注解 定义组件查找规则 --context:component-scan base-packagecom.netqincontext:include-filter typeannotationexpressionorg.springframework.stereotype.Controller /context:include-filter typeannotationexpressionorg.springframework.stereotype.Service /context:include-filter typeannotationexpressionorg.springframework.stereotype.Repository //context:component-scan!-- 视图查找器 --bean idviewResolverclassorg.springframework.web.servlet.view.InternalResourceViewResolverproperty nameviewClassvalueorg.springframework.web.servlet.view.JstlView/propertyproperty nameprefix value/WEB-INF/jsp//propertyproperty namesuffix value.jsp/property/bean!-- 加载ehcache缓存配置文件 说明在这里我遇到了这样一个问题当使用Service等注解的方式将类声明到配置文件中时就需要将缓存配置import到主配置文件中否则缓存会不起作用如果是通过bean声明到配置文件中时则只需要在web.xml的contextConfigLocation中加入applicationContext-ehcache.xml即可不过还是推荐使用如下方式吧因为这样不会有任何问题--import resourceclasspath:applicationContext-ehcache.xml/ /beansok我们接着编写applicationContext-ehcache.xml还记得之前介绍的基于命名空间的配置吗如下 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:ehcachehttp://www.springmodules.org/schema/ehcachexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsdehcache:config configLocationclasspath:ehcache.xmlidcacheProvider /ehcache:annotations providerIdcacheProviderehcache:caching cacheNametestCache idtestCaching /ehcache:flushing cacheNamestestCache idtestFlushing //ehcache:annotations/beansehcache.xml如下 ?xml version1.0 encodingUTF-8? ehcache xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:noNamespaceSchemaLocationehcache.xsd updateChecktruemonitoringautodetectdiskStore pathjava.io.tmpdir/defaultCachemaxElementsInMemory10000eternalfalsetimeToIdleSeconds120timeToLiveSeconds120overflowToDisktruemaxElementsOnDisk10000000diskPersistentfalsediskExpiryThreadIntervalSeconds120memoryStoreEvictionPolicyLRU/cache nametestCachemaxElementsInMemory10000maxElementsOnDisk1000eternalfalseoverflowToDisktruediskSpoolBufferSizeMB20timeToIdleSeconds300timeToLiveSeconds600memoryStoreEvictionPolicyLFU/ /ehcacheok配置文件都完成了接着我们来编写controller、service和dao 1.CacheDemoController package com.netqin.function.cacheDemo;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping;Controller public class CacheDemoController {Autowiredprivate CacheDemoService service;RequestMapping(/demo.do)public String handleIndex(Model model) {System.out.println(service.getName(0));model.addAttribute(name, service.getName(0));return cacheDemo;}RequestMapping(/demoFulsh.do)public String handleFulsh(Model model) {service.flush();return cacheDemo;} }2.CacheDemoService package com.netqin.function.cacheDemo;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springmodules.cache.annotations.CacheFlush; import org.springmodules.cache.annotations.Cacheable;Service public class CacheDemoService {Autowiredprivate CacheDemoDao dao;Cacheable(modelId testCaching)public String getName(int id){System.out.println(Processing testCaching);return dao.getName(id);}CacheFlush(modelId testFlushing)public void flush(){System.out.println(Processing testFlushing);}}我们只对service层加入了注解缓存配置。   接着我们来写一个简单的页面cacheDemo.jsp % page languagejava contentTypetext/html; charsetUTF-8pageEncodingUTF-8% !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd html head meta http-equivContent-Type contenttext/html; charsetUTF-8 titleInsert title here/title /head body CacheDemo:${name} /body /htmlok一切就绪我们启动服务器并访问http://localhost:8080/cache/demo.do   多请求几次请求两次的输出结果 Processing testCachingNameId:0NameId:0   说明缓存起作用了ok   接着我们刷新该缓存访问http://localhost:8080/cache/demoFulsh.do 再请求http://localhost:8080/cache/demo.do 输出结果 Processing testCachingNameId:0NameId:0Processing testFlushingProcessing testCachingNameId:0   缓存刷新成功。转载于:https://www.cnblogs.com/wcyBlog/p/3949709.html
http://www.zqtcl.cn/news/580933/

相关文章:

  • 网站开发免费中建建设银行网站
  • 301重定向到新网站在线建站
  • 曰本做爰l网站沙朗做网站公司
  • 广州网站设计智能 乐云践新专家wordpress 头像设置
  • 电子商务学网站建设好吗佛山市手机网站建设企业
  • 为企业做网站电话开场白小说网站的里面的搜索是怎么做的
  • 深圳市设计网站公司自己做网站开网店
  • 智能建站cms管理系统修改wordpress时区
  • 站长怎么添加网站内容重庆网站推
  • 东莞网站建设属于什么专业网页设计代码书
  • 网站后台代码在哪修改wordpress添加搜索小工具
  • 爱站站长工具中国建设监理协会官方网站
  • 珠海微信网站开发东莞网站制作方案定制
  • 大学网站建设说明书记的网站域名
  • 网站如何开通支付功能第一ppt课件免费下载官网
  • 做1元夺宝网站挣钱吗美工网站设计收费
  • 华侨城网站开发wordpress页码颜色
  • 上海建站网络公司制作文字图片
  • 平台型网站制作网站建设张世勇
  • 网站建设云南网页游戏大厅都有哪些
  • 网站建设与管理报告书郑州建设银行网站
  • 做网站网页的人是不是思维公司网站建设包括
  • 网站建设都包括哪些网站后台如何上传文件
  • 网站便民服务平台怎么做迁安做网站中的cms开发
  • 做外贸比较好的网站怎么把网站做的好看
  • 有没有在淘宝找人做网站被骗过的台州市环保局网站开发区
  • 公司外文网站制作河南住房和城乡建设厅网站
  • 东莞做网站公司有哪些代码网站推荐
  • 棋类游戏网站开发网站首页顶部图片尺寸
  • 工信部如何查网站备案大连网络推广广告代理