2

EDIT: This is on spring 3.1.0

I've seen other questions on this subject, and tried a few things but nothing seems to work for me.

I plan to add my version number to the path of static resources, to force requests from browsers on new versions, so I started doing as instructed on this part of the spring documentation.

Before any change, the path <context>/assets/js/base/lib/jquery-1.7.2.js works and points to an existing file.

What I did was add to my java config class the following:

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

The plan was to use the version number, instead of just my-assets once I get it to work. But it didn't, even though my logs said:

17:28:56,077  INFO [SimpleUrlHandlerMapping] Mapped URL path [/my-assets/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

I then tried some variations:

.. ("/my-assets/**").addResourceLocations("/assets/");

.. ("/my-assets/js/base/lib/**").addResourceLocations("/assets/js/base/lib/");

.. ("/my-assets/js/base/lib/**").addResourceLocations("/assets/js/base/lib/**");

And even tried adding these afterwards:

registry.setOrder(Ordered.LOWEST_PRECEDENCE); registry.setOrder(Ordered.HIGHEST_PRECEDENCE);

To no avail. In all cases <context>/assets/js/base/lib/jquery-1.7.2.js still worked and <context>/my-assets/js/base/lib/jquery-1.7.2.js didn't.

This is my directory structure:

├── assets
│   ├── charts
│   ├── css
│   ├── font
│   ├── images
│   └── js
├── META-INF
└── WEB-INF
    ├── jsp
    ├── layout
    └── tags

Any thoughts on what could be the issue?

Thanks!

Sergio
  • 671
  • 5
  • 10
  • 2
    Spring 4.1 has a versioning resource manager FYI http://www.infoq.com/presentations/resource-spring-mvc-4-1 – Neil McGuigan Mar 26 '15 at 22:51
  • Thanks Neil! We're using 3.1 and can't upgrade right now, but I'll keep that in mind. It will surely make things easier. – Sergio Mar 27 '15 at 12:47
  • 1
    Have you ruled out your DispatcherServlet not correctly registering the requests? http://stackoverflow.com/questions/25061237/spring-4-addresourcehandlers-not-resolving-the-static-resources – seanhodges Mar 27 '15 at 13:12
  • That was it @seanhodges! I totally forgot my dispatcher had the URL pattern `/app/*`! Adding this to my requests made it work! Would you post an answer so I can mark it? Thanks! – Sergio Mar 27 '15 at 14:30

0 Answers0