Spring Boot thymeleaf静态内容未加载

时间:2018-10-24 17:28:25

标签: spring-boot thymeleaf static-content

我正在努力理解为什么通过浏览器打开网页时http://localhost:8080/1/reset-password/{hereComesToken}

不能加载我的静态内容(css,图像)的原因

我在浏览器的控制台中遇到以下错误: enter image description here

使用intellij,这是我的资源文件夹:

enter image description here

已加载html内容,但未加载图像内容。

这是html图像标签:

<body>
    <div class="content">
        <img th:src="@{/images/image.jpg}" src="../static/images/image.jpg" alt="image not found"/>
    </div><!-- CONTENT -->
</body>

我扩展了WebMvcConfigurationSupport并添加了资源处理程序:

@Configuration
@EnableWebMvc
public class CustomMVCConfigurerAdapter extends WebMvcConfigurationSupport {

    @Override
    protected void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new ImageTypeConverter());
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String[] STATIC_RESOURCE = {"/", "classpath:/", "classpath:/META-INF/resources/", "classpath:/META-INF/resources/webjars/",
                "classpath:/resources/", "classpath:/static/", "classpath:/public/"};

        if (!registry.hasMappingForPattern("/**")) {
            registry.addResourceHandler("/**").addResourceLocations(STATIC_RESOURCE);
        }
    }
}

我打开了网页源页面,这就是我得到的:

enter image description here

0 个答案:

没有答案