【发布时间】:2020-11-11 19:21:17
【问题描述】:
我一直在尝试使我的 css 文件与 Spring Boot 和 Thymeleaf(甚至没有 Thymeleaf)一起工作,但它根本不起作用。
我在 StackOverFlow 上检查了很多答案,尝试了所有方法,但仍然无法正常工作。这是我所做的一个示例:
我的 test.html :
<!doctype>
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
</head>
<body>
<div>
<p class="test">trololo</p>
</div>
</body>
</html>
index.css:
* {
margin: 0;
padding: 0;
}
.test {
color: red;
}
百里香,我也试过:
<link rel="stylesheet" type="text/css" th:href="@{/css/index.css}" />
我的 css 文件位于 resources/static/css/index.css 中(我已经尝试过了,因为这是来自 stackoverflow 的人建议的),但没有运气。
我也有一个 SecurityController :
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/**").permitAll();
}
}
我设法从终端获取的唯一警告是这个:
2020-07-22 05:19:51.148 WARN 42426 --- [nio-8080-exec-2] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.servlet.NoHandlerFoundException: No handler found for GET /css/index.css]
2020-07-22 05:19:51.166 WARN 42426 --- [nio-8080-exec-3] o.s.web.servlet.PageNotFound : No mapping for GET /favicon.ico
2020-07-22 05:19:51.166 WARN 42426 --- [nio-8080-exec-3] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.servlet.NoHandlerFoundException: No handler found for GET /favicon.ico]
我的 application.properties :
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**
如果您遇到同样的问题,我很乐意寻求帮助。
谢谢!
编辑:找到了一些东西。我已经在下面发布了。
【问题讨论】:
-
您应该将您的解决方案作为答案发布,而不是将答案留在问题中。这将帮助其他人在未来找到您的解决方案。 (也许您还可以添加一句话,解释为什么它可以解决问题。)
-
@andrewjames :是的,你是对的,我应该这样做,对不起!至于解释为什么它解决了这个问题,我完全不知道,我不想误导人们。
标签: java html css spring-boot thymeleaf