spring3.1+ehcache配置问题

问题描述

ehcache主配置如下:<!-- 配置ehcache缓存管理器 --><bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"><property name="configLocation" value="classpath:ehcache/ehcache.xml" /><property name="shared" value="true"/></bean><!-- 配置一个简单的缓存工厂bean对象 --><bean id="simpleCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean"> <property name="cacheManager" ref="cacheManager" /> <!-- 使用缓存 关联ehcache.xml中的缓存配置 --> <property name="cacheName" value="mobileCache" /></bean><!-- 配置一个缓存拦截器对象,处理具体的缓存业务 --><bean id="methodCacheInterceptor" class="com.scxxs.ehcache.MethodCacheInterceptor"> <property name="cache" ref="simpleCache"/></bean><!-- 配置一个缓存拦截器对象,处理具体的缓存业务 --><bean id="methodCacheAfterAdvice" class="com.scxxs.ehcache.MethodCacheAfterAdvice"> <property name="cache" ref="simpleCache"/> </bean><!-- 参与缓存的切入点对象 (切入点对象,确定何时何地调用拦截器) --><bean id="methodCachePointCut" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <!-- 配置缓存aop切面 --> <property name="advice" ref="methodCacheInterceptor" /> <!-- 配置哪些方法参与缓存策略 --> <!-- .表示符合任何单一字元
解决方案二:
+表示符合前一个字元一次或多次
解决方案三:
*表示符合前一个字元零次或多次
解决方案四:
Escape任何Regular expression使用到的符号 --> <!-- .*表示前面的前缀(包括包名) 表示print方法--> <property name="patterns"> <list> <!-- <value>com.scxxs.dao.*get*</value><value>com.scxxs.dao.*find*</value><value>com.scxxs.dao.*query*</value> --> <value>.*find.*</value> </list> </property></bean><!-- 当发生create,save,insert,update,delete,remove等方法时,就会去flush一下 --><bean id="methodCachePointCutAdvice" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <property name="advice" ref="methodCacheAfterAdvice" /> <property name="patterns"> <list> <value>.*add.*</value> </list> </property> </bean>ehcache.xml配置如下:<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd"> <!-- 设置缓存文件 .data 的创建路径。 如果该路径是 Java 系统参数,当前虚拟机会重新赋值。 下面的参数这样解释: user.home – 用户主目录 user.dir – 用户当前工作目录 java.io.tmpdir – 默认临时文件路径 --> <diskStore path="java.io.tmpdir"/> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="30" timeToLiveSeconds="30" overflowToDisk="false"/> <!-- 配置自定义缓存 maxElementsInMemory:缓存中允许创建的最大对象数 eternal:缓存中对象是否为永久的,如果是,超时设置将被忽略,对象从不过期。 timeToIdleSeconds:缓存数据的钝化时间,也就是在一个元素消亡之前, 两次访问时间的最大时间间隔值,这只能在元素不是永久驻留时有效, 如果该值是 0 就意味着元素可以停顿无穷长的时间。 timeToLiveSeconds:缓存数据的生存时间,也就是一个元素从构建到消亡的最大时间间隔值, 这只能在元素不是永久驻留时有效,如果该值是0就意味着元素可以停顿无穷长的时间。 overflowToDisk:内存不足时,是否启用磁盘缓存。 memoryStoreEvictionPolicy:缓存满了之后的淘汰算法。 --> <cache name="SimplePageCachingFilter" maxElementsInMemory="10000" eternal="false" overflowToDisk="false" timeToIdleSeconds="900" timeToLiveSeconds="1800" memoryStoreEvictionPolicy="LFU" /> <cache name="mobileCache" maxElementsInMemory="10000" eternal="false" overflowToDisk="true" timeToIdleSeconds="1800" timeToLiveSeconds="3600" memoryStoreEvictionPolicy="LFU" /></ehcache>applicationContext.xml spring主配置如下:<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://127.0.0.1:3306/mytest</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>root</value> </property> </bean> <!-- 配置事务管理器 --><bean id="transcationManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:ibatis/SqlMapConfig.xml" /> <!--src/ WEB-INF/<property name="mapperLocations" value="classpath*:com/xxt/ibatis/dbcp/domain/user.map.xml"/ > --> </bean><bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg index="0" ref="sqlSessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="transcationManager"><tx:attributes><tx:method name="insert*" propagation="REQUIRED" /><tx:method name="del*" propagation="REQUIRED" /><tx:method name="update*" propagation="REQUIRED" /><tx:method name="*" read-only="true" /></tx:attributes></tx:advice><!-- 配置AOP切入点 --><aop:config><aop:pointcut id="allManagerMethod"expression="execution(* com.scxxs.dao.*.*(..))" /><aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" /></aop:config><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource"> <ref local="dataSource"/> </property> </bean><import resource="spring/applicationContext_dao.xml"/><import resource="spring/applicationContext_biz.xml"/><import resource="spring/applicationContext_ehcache.xml"/>我遇到的问题就是,ehcache在配置两个切面的时候报错:2013-01-06 14:33:38Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1aaf64d: defining beans [dataSource,transcationManager,sqlSessionFactory,sqlSession,txAdvice,org.springframework.aop.config.internalAutoProxyCreator,allManagerMethod,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,jdbcTemplate,springDemoDao,userDao,userBiz,cacheManager,simpleCache,methodCacheInterceptor,methodCacheAfterAdvice,methodCachePointCut,methodCachePointCutAdvice]; root of factory hierarchy2013-01-06 14:33:38Retrieved dependent beans for bean 'cacheManager': [simpleCache]2013-01-06 14:33:38Retrieved dependent beans for bean 'simpleCache': [methodCacheAfterAdvice]2013-01-06 14:33:38Retrieved dependent beans for bean 'methodCacheAfterAdvice': [methodCachePointCutAdvice]2013-01-06 14:33:38Invoking destroy() on bean with name 'cacheManager'2013-01-06 14:33:38Shutting down EHCache CacheManager2013-01-06 14:33:38Context initialization failedorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodCachePointCut' defined in class path resource [spring/applicationContext_ehcache.xml]: Cannot resolve reference to bean 'methodCacheInterceptor' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodCacheInterceptor' defined in class path resource [spring/applicationContext_ehcache.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'net.sf.ehcache.Cache' for property 'cache'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [net.sf.ehcache.Cache] for property 'cache': no matching editors or conversion strategy foundat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:452)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.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334)at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)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:566)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: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodCachePointCut' defined in class path resource [spring/applicationContext_ehcache.xml]: Cannot resolve reference to bean 'methodCacheInterceptor' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodCacheInterceptor' defined in class path resource [spring/applicationContext_ehcache.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'net.sf.ehcache.Cache' for property 'cache'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [net.sf.ehcache.Cache] for property 'cache': no matching editors or conversion strategy foundat 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)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:197)at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:86)at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:100)at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:107)at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:278)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:880)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:852)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:446)... 34 moreCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodCacheInterceptor' defined in class path resource [spring/applicationContext_ehcache.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'net.sf.ehcache.Cache' for property 'cache'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [net.sf.ehcache.Cache] for property 'cache': no matching editors or conversion strategy foundat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)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)... 50 moreCaused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'net.sf.ehcache.Cache' for property 'cache'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [net.sf.ehcache.Cache] for property 'cache': no matching editors or conversion strategy foundat org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:485)at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:516)at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:510)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1406)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1365)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)... 56 moreCaused by: java.lang.IllegalStateException: Cannot convert value of type [$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [net.sf.ehcache.Cache] for property 'cache': no matching editors or conversion strategy foundat org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:241)at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:470)... 62 more2013-1-6 14:33:38 org.apache.catalina.core.StandardContext listenerStart严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodCachePointCut' defined in class path resource [spring/applicationContext_ehcache.xml]: Cannot resolve reference to bean 'methodCacheInterceptor' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodCacheInterceptor' defined in class path resource [spring/applicationContext_ehcache.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'net.sf.ehcache.Cache' for property 'cache'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [net.sf.ehcache.Cache] for property 'cache': no matching editors or conversion strategy foundat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:452)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.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334)at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)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:566)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: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodCachePointCut' defined in class path resource [spring/applicationContext_ehcache.xml]: Cannot resolve reference to bean 'methodCacheInterceptor' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodCacheInterceptor' defined in class path resource [spring/applicationContext_ehcache.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'net.sf.ehcache.Cache' for property 'cache'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [net.sf.ehcache.Cache] for property 'cache': no matching editors or conversion strategy foundat 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)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:197)at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:86)at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:100)at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:107)at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:278)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:880)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:852)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:446)... 34 moreCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodCacheInterceptor' defined in class path resource [spring/applicationContext_ehcache.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'net.sf.ehcache.Cache' for property 'cache'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [net.sf.ehcache.Cache] for property 'cache': no matching editors or conversion strategy foundat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)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)... 50 moreCaused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'net.sf.ehcache.Cache' for property 'cache'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [net.sf.ehcache.Cache] for property 'cache': no matching editors or conversion strategy foundat org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:485)at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:516)at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:510)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1406)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1365)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)... 56 moreCaused by: java.lang.IllegalStateException: Cannot convert value of type [$Proxy4 implementing net.sf.ehcache.terracotta.InternalEhcache,net.sf.ehcache.store.StoreListener,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [net.sf.ehcache.Cache] for property 'cache': no matching editors or conversion strategy foundat org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:241)at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:470)... 62 more我试过删除一个切面的话项目是能够完全启动的,<!-- 配置一个简单的缓存工厂bean对象 --><bean id="simpleCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean"> <property name="cacheManager" ref="cacheManager" /> <!-- 使用缓存 关联ehcache.xml中的缓存配置 --> <property name="cacheName" value="mobileCache" /></bean><!-- 参与缓存的切入点对象 (切入点对象,确定何时何地调用拦截器) --><bean id="methodCachePointCut" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> <!-- 配置缓存aop切面 --> <property name="advice" ref="methodCacheInterceptor" /> <!-- 配置哪些方法参与缓存策略 --> <!-- .表示符合任何单一字元
解决方案五:
+表示符合前一个字元一次或多次
解决方案六:
*表示符合前一个字元零次或多次
解决方案七:
Escape任何Regular expression使用到的符号 --> <!-- .*表示前面的前缀(包括包名) 表示print方法--> <property name="patterns"> <list> <!-- <value>com.scxxs.dao.*get*</value><value>com.scxxs.dao.*find*</value><value>com.scxxs.dao.*query*</value> --> <value>.*find.*</value> </list> </property></bean>像上面这种配置有两个删除其中一个都没问题。我还测试过缓存起作用没,当我删除后面那个after切面后项目正常启动且缓存起作用,请教各位大虾为了我两个切面都存在的时候就要报错,报错信息就是上面那种,搞不懂啊!!!!

解决方案

<!-- 配置动态代理, 使用cglib代理所有的缓存方法. --><bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"><property name="proxyTargetClass" value="true" /><property name="beanNames"><list><value>*DAO</value><value>*Dao</value></list></property><property name="interceptorNames"><list><value>methodCachePointCut</value><value>flushCachePointCut</value></list></property></bean> 增加一个类似的bean配置, 加入cglib包. 去拿cglib 2下面的最新包. 在效率和内存使用上都有提高.

时间: 2024-09-20 18:01:24

spring3.1+ehcache配置问题的相关文章

spring3 与hibernate配置问题

问题描述 org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'loginController':Injectionofautowireddependenciesfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Couldnotautowirefield:privatenet.v

WebSphere 8.5中CXF2.5.2+Spring3.0的配置问题

问题描述 [8/22/1513:09:24:399CST]00000045WASSessionCorISessionContextRegistrygetSessionContextSESN0176I:Willcreateanewsessioncontextforapplicationkeydefault_hostUWC[8/22/1513:09:24:431CST]00000045jspWcom.ibm.ws.jsp.webcontainerext.WASJSPExtensionProcesso

spring3.1整合 EhCache的问题

问题描述 我想获取到 ehcahe的cacheManager ,但是查看org.springframework.cache.ehcache.EhCacheCacheManager 这个类里面对 ehcahe的cacheManager 只有set方法,没有get方法.求大牛指教! 解决方案 不是有的吗?你看的哪个版本的源码?public class EhCacheCacheManager extends AbstractCacheManager {public net.sf.ehcache.Cac

求救!!!spring3+hibernate3.3事务配置问题

问题描述 <?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p&q

spring-hibernate cache配置问题

问题描述 hibernate cache配置问题 求各位大神帮忙.. WARN: HHH020003: Could not find a specific ehcache configuration for cache named [org.hibernate.cache.internal.StandardQueryCache]; using defaults. <property name="hibernateProperties"> <props> <

Spring3.x企业应用开发_IOC

Ioc概念: 包括两个内容:控制&反转 对于软件来说,是某一接口具体实现类的选择控制权从调用类中移除,转交给第三方决定.DI(依赖注入:Dependency Injection)即让调用类对某一接口实现类的依赖由第三方(容器或协作类)注入,以移除调用类对某一接口实现类的依赖. Ioc类型:从注入方法上看,主要可以划分为三种类型:构造函数注入.属性注入和接口注入. 反射在Ioc中的应用,小例子: Car.class [html] view plain copy  print? package co

ehcache +mybatis+spring 自定义缓存策略

从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对事务管理的支持.Spring Cache是作用在方法上的,其核心思想是这样的:当我们在调用一个缓存方法时会把该方法参数和返回结果作为一个键值对存放在缓存中,等到下次利用同样的参数来调用该方法时将不再执行该方法,而是直接从缓存中获取结果进行返回.所以在使用Spring Cache的时候我们要保证我们缓存的方法对于相同的方法参数要有相同的返回结果.        使用Spring Cache需要我们做两方面的事

Spring3+hibernate4配置二级缓存的问题

问题描述 Spring3+hibernate4配置二级缓存的问题 com/wjh/po/AfterPostPO.hbm.xmlcom/wjh/po/LogPO.hbm.xmlcom/wjh/po/PostPO.hbm.xmlcom/wjh/po/UserPO.hbm.xml org.hibernate.dialect.MySQLDialecttruefalseupdatetruetrue spring3+hibernate4 配置ehcache二级缓存只要一把上面的二级缓存配置的注释部分去掉,访

mybatis3.0+spring3.1下,控制台打印sql问题。。大侠进。。

问题描述 刚开始用的是ibatis2.3.控制台打印sql毫无压力换了mybatis3.0后,控制台是空空如也,啥也没网上也找了各种说法,都不行,也不知道都是忽悠人的还是配置没对没办法,只能来csdn请教了,有哪位仁兄是用mybatis3.0+spring3.1架构,后台sql打印完好的请指点一二呗...不胜感激了...成功的分都给你拉...阿门 解决方案 解决方案二:没人么..解决方案三:真的没人知道吗..解决方案四:log4j.logger.com.ibatis=DEBUG解决方案五:<!-