I'm using Spring boot 2.0.2 and Freemarker for my web application. The static content of my webapp fails to load for nested / prefixed controllers.
All of the static content (images, CSS, js) is under
/src/main/resources/static/js
/src/main/resources/static/images
/src/main/resources/static/css
Everything works great if I use this controller:
@RequestMapping(value = "/userProfile", method = RequestMethod.GET)
public ModelAndView getUser(@ModelAttribute("model") ModelAndView model,@RequestParam("userId") String userId) {
UserProfile userProfile = userService.findById(userId);
model.addObject("userProfile", userProfile);
model.setViewName("userDetails");
return model;
}
userDetails.ftl is located at /src/main/resources/templates/userDetails.ftl
However, I'm seeing 404 on the static content (js/css/images) for this controller while making a GET request from the browser.
https://localhost:8443/users/js/saveUser.js -- 404
(Please note "users" in the URL while trying to load static content)
@RequestMapping(value = "/user/profile", method = RequestMethod.GET)
public ModelAndView getUser(@ModelAttribute("model") ModelAndView model,@RequestParam("userId") String userId) {
UserProfile userProfile = userService.findById(userId);
model.addObject("userProfile", userProfile);
model.setViewName("userDetails");
return model;
}
Code of the view
<link rel="stylesheet" type="text/css" href="css/homepage.css">
<link rel="stylesheet" type="text/css" href="css/user-profile-display.css">
<script type="text/javascript" src="js/saveUser.js}"></script>
<script type="text/javascript" src="js/authenticate.js}"></script>
I've looked at the following issues but can't find a solution that would work:
How to specify prefix for all controllers in Spring Boot?
spring boot: separate REST from static content
Any help would be appreciated.