Ravi
Ravi

Reputation: 323

Spring MVC resource handler not working

I am trying to configure my spring app using java config. I followed the documentation line by line and I am getting 404 when I try to access resources. Here is my config.

@EnableWebMvc
@Configuration
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {

@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
    configurer.enable();
}

@Bean
public MultipartResolver multipartResolver() {
    return new StandardServletMultipartResolver();
}

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

Upvotes: 0

Views: 2772

Answers (1)

Pavel Horal
Pavel Horal

Reputation: 18183

You have configured default servlet request handler, but you are also configuring resource handler. Not sure how these two are supposed to play together... if your resources are on classpath, just use the resource handler and drop the default servlet handler as that will simply not work.

Upvotes: 1

Related Questions