我使用Spring Boot 1.0.2实现了一个REST服务器.我无法阻止Spring设置禁用HTTP缓存的HTTP标头.
我的控制器如下:
@Controller
public class MyRestController {
@RequestMapping(value = "/someUrl", method = RequestMethod.GET)
public @ResponseBody ResponseEntity<String> myMethod(
HttpServletResponse httpResponse) throws SQLException {
return new ResponseEntity<String>("{}", HttpStatus.OK);
}
}
Run Code Online (Sandbox Code Playgroud)
所有HTTP响应都包含以下标头:
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Expires: 0
Pragma: no-cache
Run Code Online (Sandbox Code Playgroud)
我已尝试以下方法删除或更改这些标头:
setCacheSeconds(-1)控制器.httpResponse.setHeader("Cache-Control", "max-age=123")控制器.@Bean返回值.WebContentInterceptorsetCacheSeconds(-1)spring.resources.cache-period为-1或正值application.properties.以上都没有任何影响.如何在Spring Boot中为所有或单个请求禁用或更改这些标头?
我希望为一些静态资源启用HTTP缓存,例如图像,其访问受到Spring Security的限制.(这些资源不是安全关键,但也不应公开访问).如何避免让Spring Security添加禁用缓存的HTTP响应头?
如果我添加setCachePeriod()到我的资源处理程序注册WebMvcConfigurerAdapter.addResourceHandlers()如下:
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/").setCachePeriod(3600);
Run Code Online (Sandbox Code Playgroud)
仍然返回资源以及禁用缓存的以下标头:
Cache-Control: max-age=3600, must-revalidate
Expires: Mon, 04 Aug 2014 07:45:36 GMT
Pragma: no-cache
Run Code Online (Sandbox Code Playgroud)
我想避免在项目中引入任何XML配置,该项目目前仅使用Java注释配置.
有没有比扩展Spring资源处理程序更好的解决方案?
我有一个Spring Security版本3.2.3应用程序,它可以监听HTTP和HTTPS.我希望将对HTTP端口的任何请求重定向到HTTPS.如何仅使用Java配置?
Spring Security javadocHttpSecurity提出了以下解决方案(修剪为必要的):
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) {
http.channelSecurity().anyRequest().requiresSecure();
}
}
Run Code Online (Sandbox Code Playgroud)
但是这没有用,因为HttpSecurity没有方法channelSecurity().
我需要在 IntelliJ 中设置一个检查,它将找到没有 `id 属性的 xhtml/html/jsf 页面元素。
<h:outputText value="myOutputValue"
styleClass="someStyle"/>
<h:outputText value="myOtherOutputValue" />
Run Code Online (Sandbox Code Playgroud)
我尝试在“结构搜索”下的 intelliJ 中设置代码检查。但是使用以下正则表达式我无法正确配置它。任何帮助,将不胜感激。
<(?:h:inputText|h:outputText)(?:\s+(?!id\b)[\w\-.:]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[\w\-.:]+))?)*\s*/?>
Run Code Online (Sandbox Code Playgroud)
我知道正则表达式可以工作,因为当输入到查找框中时,它会在我的文件中找到出现的情况。
最后一件事,最后我想扩展(?:h:inputText|h:outputText)以包含大量标签,因此如果在检查中使用变量或 intelliJ 中的其他内容,那么该解决方案将是最好的。我们希望确保所有开发人员都id在所有适用的页面元素上添加属性,以帮助测试轻松进行。(JSF标签很难看)