EnableWebMvc annotations interrupt loading static resources from a separate jar

I used the tutorial https://blog.jdriven.com/2016/12/angular2-spring-boot-getting-started/ to create a webapp using Angular CLI and Spring Boot. With some tweaks, I was able to wage the backend project into a war with the frontend code included in the jar (which is included in the war / WEB-INF / lib directory). The webapp loads as expected unless the tutorial code changes.

Using this project as a template, I tried to migrate one of our existing projects. However, when I load the web application, I get a 404 error. I was able to trace this issue back to me using the @EnableWebMvc annotation in my config class. If this annotation is used, it seems that static resources in my front panel are not loading.

This problem persists even when I explicitly add the resource location.

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

      

I can check that my index.html is in the / static directory in my front end jar. I've looked at various answers here and adding the resource location should have fixed this problem; it is clear that something else is missing here.

I am using Spring Boot 1.5.3 and deploying to Tomcat. Thank!

+3


source to share





All Articles