Java 在Spring中将缓存头添加到响应中

Java 在Spring中将缓存头添加到响应中,java,spring,caching,servlets,cache-control,Java,Spring,Caching,Servlets,Cache Control,我有一个小的JavaSpring项目,它是一个返回xml响应的API。 想要将缓存控制头添加到响应中,但我无法找到如何添加。 我可以将标题添加到响应中,还是必须将其移动到MVC @RequestMapping(method=RequestMethod.GET,value="/search/discountsall", produces="application/xml") public ModelAndView searchAll() { SearchDiscounts

我有一个小的JavaSpring项目,它是一个返回xml响应的API。 想要将缓存控制头添加到响应中,但我无法找到如何添加。 我可以将标题添加到响应中,还是必须将其移动到MVC

@RequestMapping(method=RequestMethod.GET,value="/search/discountsall", 
        produces="application/xml")
public ModelAndView searchAll() {
    SearchDiscounts discounts = new SearchDiscounts();

    discounts = serviceFacade.getAll();

    ModelAndView mav = new ModelAndView("xmlView");
    mav.addObject("discounts", discounts);

    return mav;
}
下面是我的rest-servlet.xml标题:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context 
                           http://www.springframework.org/schema/context/spring-context.xsd">


HttpServletResponse
作为参数添加到
searchAll
方法中,您可以做任何您想做的事情。但是,如果您希望能够重用该逻辑,您可能需要使用
HandlerInterceptor
或普通servlet
筛选器
。谢谢@M.Deinum我应该添加什么库?我在import org.springframework.web.servlet上找不到任何对HttpServletResponse的引用。这是一个标准的servlet类,与Spring无关。可能的重复项