title: Accessing controlleradvice objects from another controller
body: <p>I've got a <code>@ControllerAdvice</code> class what I use to set user profile information all across the application. In this way, I get the user profile in every single JSP. However, I'm trying to access to that object in a <code>@Controller</code> like this with no success:</p>
  
  <pre><code>@ControllerAdvice
  public class CommonControllerAdvice {
  
      @ModelAttribute("PROFILE")
      public Profile populateUserProfile(HttpSession session){
          return (Profile) session.getAttribute("PROFILE");
      }
  }
  
  
  @Controller
  public class ActivityController {
  
      @GetMapping("/view/activity/{id}")
      public ModelAndView getActivity(ModelAndView modelAndView, @PathVariable Integer id) {
          Profile profile = (Profile) modelAndView.getModel().get("PROFILE");
      ... ...
      }
  }
  </code></pre>
  
  <p>But I only get a <code>NullPointerException</code> because the profile is null. However, I know that it is not <code>null</code> because I can use it in the related JSP. </p>