java - springboot无法加载静态资源文件404
PHP中文网
PHP中文网 2017-04-18 10:27:01
0
3
566

配置内容如下

重写了静态资源的资源路径
public class ResourcesConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        //registry.addResourceHandler("*.css").addResourceLocations("classpath:/static/css/");
    }
}

并且配置了:
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**
spring.resources.static-locations=classpath:/static/css/,classpath:/static/images/,classpath:/static/js/


结构如下:
src/main/java
src/main/resources/
src/main/resources/static/css/*.css
src/main/resources/static/images/*.png
src/main/resources/static/js/*.js

但是还是无法加载静态资源文件,404 异常。。。。

这个是我的jar包解压的情况,跟你的不一样啊。。。

PHP中文网
PHP中文网

认证0级讲师

reply all(3)
伊谢尔伦

There is no need to configure static, springboot will load static into the classpath by default
Source code directory

Unzip the directory into a jar package

迷茫

Try adding a template engine, such as thymeleaf, and the default configuration of springboot is like yours

巴扎黑

No configuration, just use static or other folders

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template