1

After I update my web application from Spring 4.1.0 to 4.1.2, the resource mapping stop working.

Without any change, each request to any resource is returning "HTTP 404 - NOT FOUND"(.js, .png, etc...).

Then I switch back to Spring 4.1.0, and everything becomes to work again.

This is my application configuration class:

public class MvcConfiguration extends WebMvcConfigurationSupport {

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

}

This question is similar to this: Resource Not Found after Spring 4.1.2 Update when deploy with JRebel 6.0.0

My resources are at:

  • [project]\WebContent\resources

And this is my servlet initializer:

public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer implements HttpSessionListener {

    private static final int MAX_UPLOAD_SIZE = 1 * 1024 * 1024; // 1mb;

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[] { MvcConfiguration.class };
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return null;
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] { "/" };
    }

    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter();
        encodingFilter.setEncoding("UTF-8");
        encodingFilter.setForceEncoding(true);

        return new Filter[] { encodingFilter, new MultipartFilter() };
    }

    @Override
    protected void customizeRegistration(Dynamic registration) {
        File uploadDirectory = new File(System.getProperty("java.io.tmpdir"));
        MultipartConfigElement multipartConfigElement = new MultipartConfigElement(uploadDirectory.getAbsolutePath(), MAX_UPLOAD_SIZE, MAX_UPLOAD_SIZE * 2, MAX_UPLOAD_SIZE / 2);
        registration.setMultipartConfig(multipartConfigElement);
    }
Community
  • 1
  • 1
Beto Neto
  • 3,962
  • 7
  • 47
  • 81
  • Could you describe the layout of your project, where resources are located on disk, and what links are you using in templates. Also, there should be log warnings because of this, could you share some of those? – Brian Clozel Dec 04 '14 at 06:15

1 Answers1

1

Just change your resource handler to the following:

public class MvcConfiguration extends WebMvcConfigurationSupport {

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

This broke the code for me too when upgrading from Spring 4.1.1, but removing the trailing /** in Spring 4.1.6 fixed this.

Amarjeet Singh
  • 121
  • 1
  • 2