title: HttpSession in Springboot
body: <p>I have two controllers. I'm trying to put the logged user into the session in one method, and then get it in a other method. But the sessions are different, how to fix it?</p>
  
  <pre><code>@RestController
  public class UserController {
  
      @Autowired
      private UserService userService;
  
      @RequestMapping(value = "/user/signIn", method = RequestMethod.POST)
      public ResponseEntity&lt;DataUser&gt; signIn(@RequestBody @Valid SignInUser signInUser,
                                             HttpSession session) {
          User user = userService.getUser(signInUser.getEmail(), signInUser.getPassword());
          session.setAttribute("user", user);
          DataUser dataUser = new DataUser((User) session.getAttribute("user"));
          return ResponseEntity.ok(dataUser);
      }
  
  }
  
  @RestController
  public class MessageController {
  
      @Autowired
      private MessageService messageService;
  
      @RequestMapping(value = "/data/message", method = RequestMethod.POST)
      public Message save(@RequestBody NewMessage newMessage,
                          HttpSession session) {
          System.out.println(session.getAttribute("user"));
          Message message = new Message(newMessage);
          LocalDateTime dateTime = LocalDateTime.now();
          message.setDateTime(dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
          message.setNumberRating(0);
          return messageService.save(message);
      }
  
  }
  </code></pre>
  
  <p>session.getAttribute("user") is null</p>