我使用的是Spring 4.0.3.RELEASE和EHcache 2.8.1.在JBoss 7.1.1上
通过applicationContext.xml中的以下配置,我的缓存工作正常.
factorybean">
现在我想用MBean添加监视功能.我在applicationContext.xml中更改了配置,如下所示 – 添加了2个新bean“managementService”和“mbeanServer”,没有其他更改.
这是当前配置.
factorybean">
factorybean">
使用此配置,我在应用程序服务器启动时收到以下错误.
14:05:32,208 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-1) Context initialization Failed: org.springframework.beans.factory.UnsatisfiedDependencyException: **Error creating bean with name 'managementService'** defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [net.sf.ehcache.CacheManager]: Could not convert constructor argument value of type [org.springframework.cache.ehcache.EhCacheCacheManager] to required type [net.sf.ehcache.CacheManager]: 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
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'managementService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [net.sf.ehcache.CacheManager]: Could not convert constructor argument value of type [org.springframework.cache.ehcache.EhCacheCacheManager] to required type [net.sf.ehcache.CacheManager]: 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
最佳答案
您应该将ehcache bean传递给managementService bean的构造函数而不是cacheManager.如果查看cacheManager的定义,ehcache bean将作为cacheManager传递.工厂bean将提供net.sf.ehcache.CacheManager的实例.
原文链接:https://www.f2er.com/spring/432773.html