小编Sam*_*nen的帖子

如何在Spring Boot中启用HTTP响应缓存

我使用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)

我已尝试以下方法删除或更改这些标头:

  1. 呼叫setCacheSeconds(-1)控制器.
  2. 呼叫httpResponse.setHeader("Cache-Control", "max-age=123")控制器.
  3. 定义我调用的@Bean返回值.WebContentInterceptorsetCacheSeconds(-1)
  4. 将属性设置spring.resources.cache-period为-1或正值application.properties.

以上都没有任何影响.如何在Spring Boot中为所有或单个请求禁用或更改这些标头?

java spring spring-mvc spring-security spring-boot

47
推荐指数
4
解决办法
6万
查看次数

如何使用Spring MVC和Spring Security为资源处理程序启用HTTP缓存

我希望为一些静态资源启用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资源处理程序更好的解决方案?

java spring caching spring-mvc spring-security

11
推荐指数
1
解决办法
1万
查看次数

如何使用Spring Security Java配置将HTTP请求重定向到HTTPS?

我有一个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().

java security spring spring-security spring-java-config

10
推荐指数
1
解决办法
1万
查看次数

IntelliJ 检查查找没有“id”属性的标签

我需要在 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标签很难看)

jsf intellij-idea structural-search

4
推荐指数
1
解决办法
532
查看次数