I've got a method that I want to conditionally cache based on the result of a method call to another bean (which says whether or not global caching is turned on).
I've tried,using SpEL, something along the lines of
@Cacheable(condition="@someBean.isSomeBoolean()")
which requires a BeanResolver which I don't have configured. I'm OK about creating one of these programmatically but how do I configure the class I've got cacheable methods in to reference this ? The error I am currently getting is:
No bean resolver registered in the context to resolve access to bean
There's a similar post here talking about keys, not conditions.
Has anyone successfully managed to reference other beans in caching annotations ?
Suppose that someBean in a autowired bean in your class, you can use the object being invoked target to get it, try this
@Cacheable(condition="target.someBean.isSomeBoolean()")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With