Exposure of setStatisticsEnabled/setSampledStatisticsEnabled causes cache not initialized exception when chaches are defined as spring beans. [SPR-9392] #14028
The enhancement provided with #13497 causes an unintended side-effect during initialization of the cache via the factory.
When creating a cache by the factory bean, the method create cache attempts to set the properties statistics, sampledStatistics, and disabled before returning the cache. At the time this occurs the cache has not been registered with the cache manager and has not as yet been initialized. This is not a problem for disabled, but statistics & sampledStatistics both check to see if the cache has been initialized.
Would it be possible to move the code for the statistics & sampledStatistic up to afterPropertiesSet just before attempting to decorate the cache?
Obvious workaround would be to define the cache in the ehcache.xml configuration. This unfortunately is not workable for my current project.
I have emailed Jeurgen Hoeller with regard to this as well.
The text was updated successfully, but these errors were encountered:
David G commented
I think I may have found why this has become a problem.
The spring code base for 3.1.1 is using ehcache-2.0.0.
My application is attempting to use ehcache-2.5.2.
Somewhere between ehcache-2.0.0 and ehcache-2.5.2 the setStatisticsEnabled method was altered to provide propertyChange event notification semantics.
As such, it checks the method isStatisticsEnabled(). This method requires that the cache be initialized prior to calling.
As such, using Ehcache 2.5.2 with Spring 3.1.1 and attempting to set statisticsEnabled or sampledStatisticsEnabled will fail with an IllegalStateException.
Unfortunately there is no unit test coverage on this particular case as it isn't exercised within the tests.