search

Home  >  Q&A  >  body text

java - springboot无法加载静态资源文件404

配置内容如下

重写了静态资源的资源路径
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中文网2848 days ago579

reply all(3)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:29:01

    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

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:29:01

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

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 10:29:01

    No configuration, just use static or other folders

    reply
    0
  • Cancelreply