My application is build using backbone on frontend and spring framework on backend. It is a single html application. Routes are handled by backbone, so I have a backend route wi
The first thing is that your controller method that's mapped to /**
will be taking priority over any resource requests. You can address this by increasing the precedence of ResourceHandlerRegistry
. Add a call to registry.setOrder(Ordered.HIGHEST_PRECEDENCE)
in the addResourceHandlers
method of StaticResourceConfiguration
:
@Configuration
public class StaticResourceConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
registry.addResourceHandler("/js/**").addResourceLocations("/resources/js");
}
}
The second thing is that, by default, Spring Boot configures two resource handlers for you by default, one mapped to /** and one mapped to /webjars/**. Due to the change described above, this will now take priority over the method in your controller that's also mapped to /**
. To overcome this, you should turn off default resource handling via a setting in application.properties
:
spring.resources.addMappings=false