I was trying to implement cache in our springboot application. This initially was not working as this is called internally.
@Service
public class ServiceCache {
Logger logger = LoggerFactory.getLogger(ServiceCache.class);
public void test1(){
logger.info("test1");
test2(10);
}
@Cacheable(value="cache", key="#id")
public void test2(Integer id){
logger.info("test2");
}
}
So when I call test1()
from controller, cache is not working. Obviously due to proxy being created during application startup.
Now when I add @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
to the class, now it is working. Can you please let me know what exactly is happening here and is it okay to use this attribute? Thanks.