Dmitrij Kostyushko Dmitrij Kostyushko - 5 months ago 34
Java Question

Spring boot app does not serve static resources after packaging into jar

I have a application that work perfectly fine when started via ide or command line: mvn spring-boot:run. But when i package it into jar, I cannot access static resources(404 not found). I did not want to store static files in resource fouler so i don`t have to reload the server each time i need to change static file. So i used this plugin in my pom.xml:


I can see that files are being copied in two the directory "static".
This is my configuration of resource handler:

public class WebMvcConfig extends WebMvcConfigurerAdapter {

public void addResourceHandlers(ResourceHandlerRegistry registry) {

Controllers RequestMappings are working fine, problems are only with the static resources.


You should supply multiple resource locations for resolving:

public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/**").addResourceLocations("/", "classpath:/static/");