Programmatic creation of caching proxies using CacheProxyFactoryBean does not work [SPR-16295] #20842
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
John Blum opened SPR-16295 and commented
When a user attempts to create caching proxies using the
o.s.cache.interceptor.CacheProxyFactoryBean
, this fails to work.A user might want to use the
CacheProxyFactoryBean
to introduce caching behavior and logic to classes from a 3rd party library. This recently came up in a StackOverflow post. Please read the post and the answers (especially this one) for further details.Ideally, a user would be able to add caching behavior to any class, programmatically (not declaratively) using...
Unfortunately, this does not work because the internal
CacheInterceptor's
afterSingletonesInitialized()
method never gets called, thereby setting theinitialized
bit and therefore allowing the caching behavior/logic to be evaluated. As result, the target object's original operation is always invoked, forgoing any caching behavior, making any caching proxy configuration useless.This can be fixed by having
CacheProxyFactoryBean
implement theSmartInitializingSingleton
interface along withBeanFactoryAware
and delegating said operations to the internalCacheInterceptor
.See Pull Request for fix.
Affects: 4.3.13, 5.0.2
Reference URL: https://stackoverflow.com/questions/47665485/how-can-i-manually-add-a-spring-cacheinterceptor-using-java-config
Issue Links:
@EnableCaching
provokes early initialization of any config class declaring a CacheManagerReferenced from: pull request #1624, and commits b160f93, d53ede9
Backported to: 4.3.14
The text was updated successfully, but these errors were encountered: