`

Cannot convert value of type [org.springframework.cache.ehcache.EhCacheCache

 
阅读更多

错误信息:

[org.springframework.beans.factory.support.DefaultListableBeanFactory]Failed to convert bean 'cacheManager' to required type [net.sf.ehcache.CacheManager]
org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'org.springframework.cache.ehcache.EhCacheCacheManager' to required type 'net.sf.ehcache.CacheManager'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.cache.ehcache.EhCacheCacheManager] to required type [net.sf.ehcache.CacheManager]: no matching editors or conversion strategy found
 at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:71)
 at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:39)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:354)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:442)
 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)
 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:550)
 at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150)
 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1122)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:910)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:853)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:558)
 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1122)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
 at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
 at org.apache.catalina.core.StandardService.start(StandardService.java:516)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.IllegalStateException: Cannot convert value of type [org.springframework.cache.ehcache.EhCacheCacheManager] to required type [net.sf.ehcache.CacheManager]: no matching editors or conversion strategy found
 at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:264)
 at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:93)
 at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:61)
 ... 50 more

 


解决方案:
原因是因为我在service中注入的CacheManager类与spring配置的文件中的cacheManager类不一致导致的.
比如我在servcie中注入的是
import net.sf.ehcache.CacheManager;

@Resource
CacheManager cacheManager;

而且在spring配置的文件中的是
<!-- 声明cacheManager -->
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"
p:cacheManager-ref="cacheManagerFactory"/>

所以会出错,把service中的注解类改成
@Resource
EhCacheCacheManager cacheManager;

即可,然后重新启动服务器,解决此问题。

Ehcache cache =  cacheManager.getCacheManager().getEhcache("commonlinktype_cache");
if(cache.get("zhouhaitao_el_key") == null ){
 cacheManager.getCacheManager().getCache("commonlinktype_cache").put(new Element("zhouhaitao_el_key", (Serializable)"zhouhaitao_test_value"));
}else{
 try {
  Element element = cache.get("zhouhaitao_el_key");
  System.out.println(element.getValue());
 } catch (Exception e) {
  e.printStackTrace();
 }
}

分享到:
评论

相关推荐

    spring和hibernate__jar包,详细说明看jar包列表

    org.springframework.instrument.tomcat-3.1.1.RELEASE.jar org.springframework.jdbc-3.1.1.RELEASE.jar org.springframework.jms-3.1.1.RELEASE.jar org.springframework.orm-3.1.1.RELEASE.jar org.spring...

    spring-framework-3.0.5.RELEASE-dependencies-1

    spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是独立的,我列了目录,可以只下载需要的包,这是1号包: 1号包: edu.emory.mathcs.backport edu.oswego.cs....

    ehcache.xsd_ehcache.xml代码提示.rar

    软件介绍: 已测试有效的ehcache.xsd文件,引入ide中,进行ehcache.xml的代码提示。Windows外壳公用DLL文件,大小23.1KB。

    ehcache-3.9.9-API文档-中英对照版.zip

    Maven坐标:org.ehcache:ehcache:3.9.9; 标签:ehcache、jar包、java、中英对照文档; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持...

    spring-framework-3.0.5.RELEASE-dependencies-6

    spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是独立的,我列了目录, 可以只下载需要的包,这是6号包: 1号包: edu.emory.mathcs.backport edu.oswego....

    spring-framework-3.0.5.RELEASE-dependencies-7

    spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是独立的,我列了目录, 可以只下载需要的包,这是7号包: 1号包: edu.emory.mathcs.backport edu.oswego....

    spring-framework-3.0.5.RELEASE-dependencies-5

    spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是独立的,我列了目录, 可以只下载需要的包,这是5号包: 1号包: edu.emory.mathcs.backport edu.oswego....

    spring-framework-3.0.5.RELEASE-dependencies-8

    spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是独立的,我列了目录, 可以只下载需要的包,这是8号包: 1号包: edu.emory.mathcs.backport edu.oswego.cs...

    spring-framework-3.0.5.RELEASE-dependencies-3

    spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是独立的,我列了目录, 可以只下载需要的包,这是3号包: 1号包: edu.emory.mathcs.backport edu.oswego.cs...

    spring-framework-3.0.5.RELEASE-dependencies-2

    spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是独立的,我列了目录, 可以只下载需要的包,这是2号包: 1号包: edu.emory.mathcs.backport edu.oswego....

    spring-framework-3.0.5.RELEASE-dependencies-4

    spring-framework-3.0.5.RELEASE-dependencies 好不容易找到了,赶紧分享一下 因为不能大于20M,共分了8个包,都是独立的,我列了目录, 可以只下载需要的包,这是4号包: 1号包: edu.emory.mathcs.backport edu.oswego....

    借助Ehcache缓存框架实现对页面的缓存Demo

    1、ehcache.xml和ehcache.xsd两个文件可以在下在下载下来的名为“ehcache-core-x.x.x-distribution.tar.gz”压缩文件中找到 2、由于要实现Ehcache缓存页面,所以必须要添加“ehcache-web-2.0.4.jar” jar包,该jar包...

    mybatis-ehcache-1.0.2.jar

    mybatis-ehcache-1.0.2.jar META-INF/LICENSE META-INF/MANIFEST.MF META-INF/NOTICE META-INF/maven/org.mybatis....org.mybatis.caches.ehcache.EhcacheCache.class org.mybatis.caches.ehcache.LoggingEhcache.class

    spring3整合EhCache注解实例

    spring3整合EhCache注解实例

    ehcahe页面缓存详细内容

    1.需要将附件中2个jar放入lib中 2.将ehcache.xml放入能加载到classpath中的任意包中,不能放入...4.启动工程 如果工程不报错,并且启动日志包含大量|net.sf.ehcache.Cache:net.sf.ehcache.Cache 类似日志说明配置成功

    ehcache-core-2.6.5.jar和mybatis-ehcache-1.0.2.jar

    ehcache.xml配置内容 &lt;ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ehcache.org/ehcache.xsd"&gt; &lt;diskStore path="java.io.tmpdir"/&gt; eternal=...

    hibernate4.0使用二级缓存jar包

    &lt;property name="hibernate.cache.region.factory_class"&gt;org.hibernate.cache.ehcache.EhCacheRegionFactory 3.3配置如下: &lt;property name="hibernate.cache.use_second_level_cache"&gt;true &lt;property name="cache...

    ehcache-3.9.9-API文档-中文版.zip

    Maven坐标:org.ehcache:ehcache:3.9.9; 标签:ehcache、jar包、java、中文文档; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,...

    ehcache.xml 文件

    ehcache.xml 文件

    mybatis ehcache 1.0 ehcache.xsd 提示文件

    mybatis 第三方二级缓存,ehcache 配置文件的 约束文件 ehcache.xsd !!

Global site tag (gtag.js) - Google Analytics