iyuohz / ehcache-spring-annotations

Automatically exported from code.google.com/p/ehcache-spring-annotations
0 stars 0 forks source link

Wrong CacheManager is looked up #40

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Define a spring bean with id "cacheManager". This bean should not be of type 
"net.sf.ehcache.CacheManager".
2. Define a spring bean of type "net.sf.ehcache.CacheManager" with another id 
e.g. "ehCacheManager".
3. Reference the "ehCacheManager" bean in the ehcache-spring-annotations 
configuration e.g. <ehcache:annotation-driven cache-manager = "ehCacheManager" 
/>

What is the expected output? What do you see instead?
You'd expect that the plugin would use the ehCacheManager bean and not the 
cacheManager bean, but instead the cacheManager is wrongfully used. It seems 
that although you referenced a specific CacheManger, if there's also a bean 
name "cacheManager" defined, it will use that bean anyhow.

Partial stacktrace:
org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 
'com.googlecode.ehcache.annotations.config.internalEhCacheEvictionTask': 
Initialization of bean failed; nested exception is 
org.springframework.beans.TypeMismatchException: Failed to convert property 
value of type [my.package.cache.CacheManagerImpl] to required type 
[net.sf.ehcache.CacheManager] for property 'cacheManager'; nested exception is 
java.lang.IllegalArgumentException: Cannot convert value of type 
[my.package.cache.CacheManagerImpl] to required type 
[net.sf.ehcache.CacheManager] for property 'cacheManager': no matching editors 
or conversion strategy found

What version of the product are you using? On what operating system?
1.1.2

Please provide any additional information below.
It seems to me that the strategy should be: if you implicitly reference a 
CacheManager as follows, <ehcache:annotation-driven cache-manager = 
"ehCacheManager" />, you should always search for and use that bean. A bean 
with id "cacheManager" should be ignored.

Original issue reported on code.google.com by timmy.st...@gmail.com on 7 Jul 2010 at 8:13

GoogleCodeExporter commented 9 years ago

Original comment by eric.dalquist on 7 Jul 2010 at 1:46

GoogleCodeExporter commented 9 years ago
I am able to replicate the problem you report by creating the following 
(incorrect) beans in a Spring applicationContext:

{{{
<ehcache:annotation-driven cache-manager="ehCacheManager" 
create-missing-caches="true"/>
<ehcache:config>
  <ehcache:evict-expired-elements interval="20"/>
</ehcache:config>

<bean id="cacheManager" class="java.lang.String">
  <constructor-arg><value>I am not a cacheManager.</value></constructor-arg>
</bean>
<bean id="ehCacheManager" 
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
</bean>
}}}

This fails because the ehcache:config element is missing the cache-manager 
attribute.
Simply change the ehcache:config element in your config to include it, like so:
{{{
<ehcache:annotation-driven cache-manager="ehCacheManager" 
create-missing-caches="true"/>
<ehcache:config cache-manager="ehCacheManager">
  <ehcache:evict-expired-elements interval="20"/>
</ehcache:config>
}}}

Original comment by nicholas.blair on 7 Jul 2010 at 5:00

GoogleCodeExporter commented 9 years ago
I have updated the wiki page for EvictExpiredElements to reflect the need to 
specify the cache-manager attribute for the config element in the same fashion 
as the annotation-driven element.

Original comment by nicholas.blair on 7 Jul 2010 at 5:09

GoogleCodeExporter commented 9 years ago
I'm marking this resolved since there hasn't been further comment and it 
appears to have been a problem in the documentation which has since been fixed.

Original comment by eric.dalquist on 9 Jul 2010 at 12:48