Css 无法使用spring提供静态资源,请改为接收索引
我有一个简单的SpringWeb应用程序Css 无法使用spring提供静态资源,请改为接收索引,css,spring-boot,thymeleaf,Css,Spring Boot,Thymeleaf,我有一个简单的SpringWeb应用程序 @Controller public class GreetingController { @Autowired GreetingRepository repository; @GetMapping("/greeting") public String greetingForm(Model model) { model.addAttribute("greeting", new Greeting());
@Controller
public class GreetingController {
@Autowired
GreetingRepository repository;
@GetMapping("/greeting")
public String greetingForm(Model model) {
model.addAttribute("greeting", new Greeting());
return "greeting";
}
@PostMapping("/greeting")
public String greetingSubmit(@ModelAttribute Greeting greeting) {
repository.save(greeting);
return "result";
}
}
HTML是:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Greeting Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" th:href="@{/css/style.css}"/>
</head>
<body>
<h1>Form</h1>
<form action="#" th:action="@{/greeting}" th:object="${greeting}" method="post">
<p>Id: <input type="text" th:field="*{id}" /></p>
<p>Message: <input type="text" th:field="*{content}" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
</body>
</html>
但是,不应用css
事实上,当我查询localhost:8080/css/style.css时,它会返回索引页的HTML内容。安全配置会阻止对资源的所有请求。相反,它将这些请求重定向到已配置的索引页 这个解决方案很简单,将所有请求授权给网站的资源/images/**和/css/**和/js/**
一旦配置好,web应用程序就会按预期工作。这可能是一个安全配置问题。在您的项目上是否有安全实现或自定义?如果是,您的用户是否有权访问/css/*url或此url具有公共访问权限?如果用户无权访问url或在处理请求时出现异常,则可能会发生重定向。您的项目上是否有安全实现或自定义?如果是,您的用户是否有权访问“/css/*”url或此url具有公共访问权限?如果用户无权访问url或在处理请求时出现异常,则可能会发生重定向。事实证明就是这样。你能把它作为答案贴出来吗?然后我可以投票给你们代表,我把它作为答案加上去了。
p {
color: #ff5588;
}