Spring @Cacheable is breaking @RequestMapping

Deadly 提交于 2019-12-06 14:02:54

Whilst @mana has explained how to fix this, this is why adding @Cacheable breaks your code. A recent blog post explains this in more detail and is well worth a read.

By default Spring creates JDK dynamic proxies to achieve the caching behaviour, this requires that the class being proxied implements an interface which declares all the methods you wish to expose on your @Cacheable class. It is worth noting that you don't have to implement any interfaces if you configure Spring to use CGLIB based proxies.

You haven't supplied any specific errors but often you get a method not found exception in this scenario. Spring tries to invoke the getBackLog() method on the proxy and there isn't one.

mana

You shouldn't cache the controller method itself but the resource hungry method that will be called to create the backlog. Have a look at this similar question. What @Cachable does is to create a key value map for your function parameters and the related return value. In your case this would be a ModelAndView object.

If you really need server side web page caching maybe use this Apache Cache Module.

NimChimpsky

you should be injecting your service class into the controller and caching the methods on the service class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!