Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 无法使用视图层加载资源_Spring_Spring Mvc_Spring Security_Thymeleaf - Fatal编程技术网

Spring 无法使用视图层加载资源

Spring 无法使用视图层加载资源,spring,spring-mvc,spring-security,thymeleaf,Spring,Spring Mvc,Spring Security,Thymeleaf,我第一次使用Thymeleaf视图层。我已经将模板的默认位置更改为WEB-INF/views,并且我的所有静态资源都位于/resources/css/目录下,它们使用spring资源处理程序映射到/css/**模式。我有一个页面,使用运行时失败的CSS文件。我得到以下例外。如果我删除标签,则页面加载时不会应用任何CSS。下面是我在页面中的链接 任何指点都将不胜感激 资源处理程序: @Override public void addResourceHandlers(ResourceHandle

我第一次使用Thymeleaf视图层。我已经将模板的默认位置更改为
WEB-INF/views
,并且我的所有静态资源都位于
/resources/css/
目录下,它们使用spring资源处理程序映射到
/css/**
模式。我有一个页面,使用运行时失败的CSS文件。我得到以下例外。如果我删除
标签,则页面加载时不会应用任何
CSS
。下面是我在页面中的链接

任何指点都将不胜感激

资源处理程序:

@Override
 public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/css/**").addResourceLocations("/resources/css/");
        registry.addResourceHandler("/js/**").addResourceLocations("/resources/js/");
 }
例外情况:

javax.servlet.ServletException: Filter execution threw an exception
    org.springframework.boot.context.web.ErrorPageFilter.handleException(ErrorPageFilter.java:135)
    org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:104)
    org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:85)
    org.springframework.boot.context.web.ErrorPageFilter.handleException(ErrorPageFilter.java:135)
    org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:104)
    org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:85)
    org.springframework.boot.context.web.ErrorPageFilter.handleException(ErrorPageFilter.java:135)

您正在使用spring boot,不需要重写
addResourceHandlers(..)
,只需将资源放入
src/main/resources/static
src/main/resources/public
src/main/resources/resources
中,这些文件夹在spring boot中默认注册

更新:

然后将其放在/WEB-INF/static或WEB-INF/resources或WEB-INF/public

上,但我不想将与WEB相关的资源放在
src/main/resources
下。我想把
CSS
相关的东西放在
/webapp/resources/CSS
里面。如何配置ThymeLeaf以从该位置读取资源?感谢更新。我设法让那部分工作起来了。但是现在我遇到了一个非常奇怪的StackOverflow错误,如果我包含一个简单的静态twitter引导代码片段,页面将无法工作。我不明白问题的本质。stacktrace的摘录没有指出问题所在。你能发布完整的stacktrace吗?