I am new to Spring and read that we can't use @Cacheable
with static method
but can't found why we can't use so any one can explain so that beginner can understood easily?
Can we use static method for retrieving database table
?
I have made static method
of all method of service layer
of DAO so Is this thread-safe
?
Elaborating on my comment:
"Static methods cannot be cached. The way aspects work in Spring is by adding a wrapper class (a proxy) to the annotated class. There is no way in Java to add a wrapper to a static method."
Since Spring needs an object to wrap around in order to intercept calls to that object and perform various operations before delegating the modified input to the original object (thus spring aspects are possible).
Since anything that is static
cannot be instantiated as an object, Spring has no way to wrap around it and intercept its calls (at least with the current implementation of Spring)
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