简体   繁体   中英

Spring boot not serving static content returns a 404 not found

Spring boot configuration.

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        ApplicationContext ctx = SpringApplication.run(Application.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
    ...
   }

Where I placed the necessary static content

在此处输入图片说明

And accessing it through my jsp

<link href="./resources/css/bootstrap.min.css" rel="stylesheet">

it returns a 404 not found. What am I missing?

Spring Boot serves static resources from directories like /static , /public or /resources . So you could put your resources into src/main/resources/static .

If you have a resource src/main/resources/static/css/bootstrap.min.css you can access it via

<link href="/css/bootstrap.min.css" rel="stylesheet">

See also the Reference Guide .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM