且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有 Thymeleaf 的 SpringBoot - 找不到 css

更新时间:2023-11-17 23:53:04

问题出在 Application.java 文件中的 @EnableWebMvc 注释.一旦我删除了那个,css 就开始在 localhost:8080/css/style.css 上可用,但没有应用.到目前为止,我还没有找到 @EnableWebMvc 导致问题的原因.

The problem was the @EnableWebMvc annotation in the Application.java file. As soon as I removed that one, the css started to be available at localhost:8080/css/style.css but was not applied. So far I haven't found the reason why the @EnableWebMvc was causing the problem.

然后我删除了一个映射到 /** 的控制器,我已经实现了该控制器以显示自定义错误页面.

Then I removed a controller mapped to /** that I had implemented in order to display custom error page.

@RequestMapping("/**")
public String notFound() {
    return "errors/404";
}

在删除这个之后,我的 css 就可以工作了.=)

After removing also this one, I've got my css working. =)