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

公司做网站价格深圳市南山区住房和建设局网站

公司做网站价格,深圳市南山区住房和建设局网站,公司网站建设北京,光明附近网站建设公司如果在网上查找使用Spring 3.1内置缓存的示例#xff0c;那么通常会碰到Spring的SimpleCacheManager #xff0c;Spring的家伙说这对“用于测试或简单的缓存声明很有用”。 实际上#xff0c;我更喜欢将SimpleCacheManager看作是轻量级的#xff0c;而不是简单的。 在您希望… 如果在网上查找使用Spring 3.1内置缓存的示例那么通常会碰到Spring的SimpleCacheManager Spring的家伙说这对“用于测试或简单的缓存声明很有用”。 实际上我更喜欢将SimpleCacheManager看作是轻量级的而不是简单的。 在您希望每个JVM占用少量内存缓存的情况下很有用。 如果Spring的家伙正在经营一家超市那么SimpleCacheManager将属于他们自己品牌的“基本”产品范围。 另一方面如果您需要一个可扩展持久和分布式的重型缓存则Spring还附带内置的ehCache包装器。 好消息是Spring的缓存实现之间的交换很容易。 从理论上讲这完全是配置问题为了证明该理论正确我从Caching和Cacheable博客中获取了示例代码并使用EhCache实现对其进行了运行。 配置步骤与我上一篇博客“ 缓存和配置”中描述的步骤相似您仍然需要指定 cache:annotation-driven / …在您的Spring配置文件中以打开缓存。 您还需要定义一个id为cacheManager的bean只是这一次您引用Spring的EhCacheCacheManager类而不是SimpleCacheManager 。 bean idcacheManagerclassorg.springframework.cache.ehcache.EhCacheCacheManagerp:cacheManager-refehcache/ 上面的示例演示了EhCacheCacheManager配置。 注意它引用了另一个ID为“ ehcache ”的bean。 配置如下 bean idehcache classorg.springframework.cache.ehcache.EhCacheManagerFactoryBeanp:configLocationehcache.xmlp:sharedtrue/ “ ehcache ”具有两个属性 configLocation和shared 。 “ configLocation ”是一个可选属性用于指定ehcache配置文件的位置。 在测试代​​码中我使用了以下示例文件 ?xml version1.0 encodingUTF-8? ehcache xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocationhttp://ehcache.org/ehcache.xsddefaultCache eternaltrue maxElementsInMemory100 overflowToDiskfalse /cache nameemployee maxElementsInMemory10000 eternaltrue overflowToDiskfalse / /ehcache …这将创建两个缓存一个默认缓存和一个名为“员工”的缓存。 如果缺少此文件则EhCacheManagerFactoryBean只需选择一个默认的ehcache配置文件 ehcache-failsafe.xml 该文件位于ehcache的ehcache-core jar文件中。 另一个EhCacheManagerFactoryBean属性是 shared 。 这被认为是可选的因为文档指出它定义了“ EHCache CacheManager是应该共享作为VM级别的单例还是独立的通常在应用程序内部。 默认值为false创建一个独立的实例。” 但是如果将其设置为false则将收到以下异常 org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframework.cache.interceptor.CacheInterceptor#0: Cannot resolve reference to bean cacheManager while setting bean property cacheManager; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name cacheManager defined in class path resource [ehcache-example.xml]: Cannot resolve reference to bean ehcache while setting bean property cacheManager; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ehcache defined in class path resource [ehcache-example.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following: 1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary 2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: InputStreamConfigurationSource [streamjava.io.BufferedInputStream424c414]at org.springframework.beans.factory.support.BeanDefinitionValueResolver. resolveReference(BeanDefinitionValueResolver.java:328)at org.springframework.beans.factory.support.BeanDefinitionValueResolver. resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. populateBean(AbstractAutowireCapableBeanFactory.java:1118)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. doCreateBean(AbstractAutowireCapableBeanFactory.java:517)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. createBean(AbstractAutowireCapableBeanFactory.java:456) ... stack trace shortened for clarityat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner. java:683)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner. run(RemoteTestRunner.java:390)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner. main(RemoteTestRunner.java:197) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name cacheManager defined in class path resource [ehcache-example.xml]: Cannot resolve reference to bean ehcache while setting bean property cacheManager; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ehcache defined in class path resource [ehcache-example.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following: 1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary 2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: InputStreamConfigurationSource [streamjava.io.BufferedInputStream424c414]at org.springframework.beans.factory.support.BeanDefinitionValueResolver. resolveReference(BeanDefinitionValueResolver.java:328)at org.springframework.beans.factory.support.BeanDefinitionValueResolver. resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360) ... stack trace shortened for clarityat org.springframework.beans.factory.support.AbstractBeanFactory. getBean(AbstractBeanFactory.java:193)at org.springframework.beans.factory.support.BeanDefinitionValueResolver. resolveReference(BeanDefinitionValueResolver.java:322)... 38 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ehcache defined in class path resource [ehcache-example.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following: 1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary 2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: InputStreamConfigurationSource [streamjava.io.BufferedInputStream424c414]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. initializeBean(AbstractAutowireCapableBeanFactory.java:1455)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. doCreateBean(AbstractAutowireCapableBeanFactory.java:519)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. createBean(AbstractAutowireCapableBeanFactory.java:456)at org.springframework.beans.factory.support.AbstractBeanFactory$1 .getObject(AbstractBeanFactory.java:294)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry. getSingleton(DefaultSingletonBeanRegistry.java:225)at org.springframework.beans.factory.support.AbstractBeanFactory. doGetBean(AbstractBeanFactory.java:291)at org.springframework.beans.factory.support.AbstractBeanFactory. getBean(AbstractBeanFactory.java:193)at org.springframework.beans.factory.support.BeanDefinitionValueResolver. resolveReference(BeanDefinitionValueResolver.java:322)... 48 more Caused by: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following: 1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary 2. Shutdown the earlier cacheManager before creating new one with same name. The source of the existing CacheManager is: InputStreamConfigurationSource [streamjava.io.BufferedInputStream424c414]at net.sf.ehcache.CacheManager.assertNoCacheManagerExistsWithSameName(CacheManager. java:521)at net.sf.ehcache.CacheManager.init(CacheManager.java:371)at net.sf.ehcache.CacheManager.(CacheManager.java:339)at org.springframework.cache.ehcache.EhCacheManagerFactoryBean. afterPropertiesSet(EhCacheManagerFactoryBean.java:104)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory. initializeBean(AbstractAutowireCapableBeanFactory.java:1452)... 55 more …当您尝试运行一系列单元测试时。 我认为这归结为Spring的ehcache管理器工厂的一个简单错误因为它试图使用new()创建多个缓存实例而不是使用“其中一种CacheManager.create静态工厂方法”作为例外允许其重用相同名称的相同CacheManager。 因此我的第一个JUnit测试工作正常但其他所有测试均失败。 令人反感的代码行是 this.cacheManager (this.shared ? CacheManager.create() : new CacheManager()); 为了完整性下面列出了我的完整XML配置文件 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beans xmlns:phttp://www.springframework.org/schema/pxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:cachehttp://www.springframework.org/schema/cache xmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsdhttp://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd!-- Switch on the Caching --cache:annotation-driven /!-- Do the component scan path --context:component-scan base-packagecaching /bean idcacheManager classorg.springframework.cache.ehcache.EhCacheCacheManager p:cacheManager-refehcache/bean idehcache classorg.springframework.cache.ehcache.EhCacheManagerFactoryBean p:configLocationehcache.xml p:sharedtrue/ /beans 在使用ehcache时要考虑的唯一其他配置详细信息是Maven依赖项。 这些非常简单因为Ehcache的专家们将所有各种ehcache jar组合到一个Maven POM模块中。 可以使用下面的XML将该POM模块添加到项目的POM文件中 dependencygroupIdnet.sf.ehcache/groupIdartifactIdehcache/artifactIdversion2.6.0/versiontypepom/typescopetest/scope/dependency 最后可以从Maven Central和Sourceforge存储库中获得ehcache Jar文件 repositoriesrepositoryidsourceforge/idurlhttp://oss.sonatype.org/content/groups/sourceforge//urlreleasesenabledtrue/enabled/releasessnapshotsenabledtrue/enabled/snapshots/repository/repositories 祝您编程愉快别忘了分享 参考 Spring 3.1来自Captain Debugs Blog博客的JCG合作伙伴 Roger Hughes的缓存和EhCache 。 翻译自: https://www.javacodegeeks.com/2012/10/spring-31-caching-and-ehcache.html
http://www.pierceye.com/news/473353/

相关文章:

  • 网站建设经费计划内容网站建设中存在的问题
  • 天凡建设股份有限公司网站苍山网站建设
  • 如何新建网站dw线下推广的渠道和方法
  • 网站友链wordpress火车头发布
  • 青海网站维护公司自己的网站叫什么
  • 微网站 淘宝客wordpress备案号放置
  • html5 手机网站 模版网站信息员队伍建设
  • 基金会网站开发方案政务公开网站建设重点
  • 影视网站制作网页游戏的软件
  • 企业做网站的费用如何科目青色网站欣赏
  • 做视频网站怎么赚钱的网站开发流程的三个部分
  • 牡丹江市建设行业协会网站广西住房城乡建设厅网站首页
  • 重庆网站关键词排名优化免费网页代理的推荐
  • 定制型网站怎么做重庆软件开发公司有哪些
  • 自适应型网站建设网站建设搭建是什么意思
  • 网站建设能够不同地方网址大全12345
  • 做网批那个网站好校园网站界面建设
  • 免费网站建设php济南网站建设公司官网
  • 徐汇网站推广网络营销的四个特点
  • 简易做网站wordpress插件tag
  • 红酒 公司 网站建设青岛安装建设股份公司网站
  • 小米路由hd 做网站营销型网站策划 建设的考试题
  • 运河网站制作自主建站平台
  • 万网 网站建设合同最好的网站开发语言
  • 网站备案密码收不到典当 网站
  • 东莞网站建设推广服务网站建设开票单位
  • 贵港公司做网站东莞凤岗企业网站建设推广
  • 网站制作过程中碰到的问题微信怎么做链接推广产品
  • 做网站留后门是怎么回事视频网站开发需求分析
  • 关于做网站的了解点电子商务应用平台包括哪些