For having a global @ModelAttribute, I am using a @ControllerAdvice, like this:
@ControllerAdvice
public class MyControllerAdvice {
@ModelAttribute("globalModelAttribute")
public String getFacebookScope() {
return "FACEBOOK_SCOPE";
}
}
Now I am able to access the globalModelAttribute in all my JSPs except those which are registered as ViewControllers, like this:
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("home");
registry.addViewController("/login").setViewName("login");
}
}
Liked to know how to go about this.
Seems that you cannot use addViewControllers("/login") because it bypass the @ControllerAdvice.
Fixed by creating a @RequestMapping for "/login".
Reference: http://nixmash.com/java/why-your-controlleradvice-may-not-be-firing/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With