【问题标题】:Spring Boot Security + GWT, static resources access 403 errorSpring Boot Security + GWT,静态资源访问403错误
【发布时间】:2017-07-23 08:29:24
【问题描述】:

我正在解决我的 gwt+spring 安全简单应用程序中的 css/js 访问问题。所以,我有下一个方法的安全控制器:

@GetMapping(value = "/notes")
public ModelAndView index(ModelAndView modelAndView) {
    modelAndView.setViewName(VIEW_NOTES);
    return modelAndView;
}

顺便说一下,我按照这个article整合了这些技术。所以,多亏了这个控制器方法(我使用 RestController),我们得到了解析视图(简单如 ****):

<!DOCTYPE html>
<html lang="en">
<head>
<title>Notes</title>
<link rel="stylesheet" type="text/css" media="all" 
href="../static/css/notes-main.css"></link>
</head>
<body>
<!-- This script tag is what actually loads the GWT module.  The -->
<!-- 'nocache.js' file (also called a "selection script") is     -->
<!-- produced by the GWT compiler in the module output directory -->
<!-- or generated automatically in development mode.             -->
<script language="javascript" src="notesgwtapp/notesgwtapp.nocache.js">
</script>
<!-- Include a history iframe to enable full GWT history support -->
<!-- (the id must be exactly as shown)                           -->
<iframe src="javascript:''" id="__gwt_historyFrame" 
style="width:0;height:0;border:0"></iframe>
<div id="notes"></div>
</body>
</html>

现在最有趣的是我有这两个错误: 获取http://localhost:8080/static/css/notes-main.css403 获取http://localhost:8080/notesgwtapp/notesgwtapp.nocache.js403

顺便说一句,我在为其他视图解析资源方面没有问题。 请帮忙,我该如何处理?如果我错过了代码的某些重要部分,我会添加它。问一下。提前谢谢你。

【问题讨论】:

    标签: spring gwt


    【解决方案1】:

    默认情况下,Sprint Boot 允许对 /js/**/css/**/images/** 的所有访问。但是您尝试访问/static/**/notesgwtapp/**,这将导致403 错误(请参阅here)。

    有两种解决方案:

    1. 确保notesgwtapp.nocache.jsnotes-main.css 文件最终位于上述文件夹之一或
    2. 覆盖 Spring Boot 应用的 SecurityConfig 并将 /static/**/notesgwtapp/** 文件夹添加到允许的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-02
      • 2016-05-04
      • 2021-10-12
      • 1970-01-01
      • 2015-08-21
      • 2016-10-01
      • 2016-07-22
      • 1970-01-01
      相关资源
      最近更新 更多