I use Spring 3.0 and ehcache. I have added @Cacheable annotations to some methods of a bean. I am injecting that bean into other beans and it is registered in my application context xml file. The application was working before adding ehcache annotations (I use com.googlecode.ehcache-spring-annotations v 1.2.0), but after adding the annotations, Spring is unable to properly inject the beans that contain the annotations. The error I see in my log file is:
org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy67 implementing java.io.Serializable,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type '{my bean type}' for property '{property}'.
Here is what I have added to my application context for ehcache to work:
<context:annotation-config />
<context:component-scan base-package="{my root package}" />
<ehcache:annotation-driven cache-manager="cacheManager" />
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
</bean>
I think the configuration is OK, because at first I had some issues loading the ehcache.xml file and there was a corresponding error in the logs for that. After I fixed the problem, I got the error above. It seems that spring creates a proxy for my bean that internally calls the caching logic for ehcache, but fails to make that proxy convertible to the bean type.
@CacheableAnnotation have a interface, and do you use the interface or the class in the other bean where the cached one is injected? - Ralph@Cacheablesupport is a Spring 3.1 feature, not supported in 3.0. Make sure that you do not usejavax.persistance.Cacheable! - Ralph@Cacheableannotation. I just discussed the issue with some colleagues and your first comment probably points to the right answer. I am using the concrete class to inject the bean, while Spring seems to bind the proxy to an interface. - Ivaylo Slavov