title: How to make spring session persistent throughout multiple requests?
body: <p>I'm developing a web application using Spring Boot and Angular (in the background I'm also using Spring Session, Security and Data Jpa). I've  encountered a problem with the session. It seems like spring is creating a new session instance for each request (I checked the session id). My question is, is there any way to prevent this from happening? I would like to store values in a session and keep them persistent throughout requests.</p>
  
  <p>This does not happen in a fresh project that only has a spring-boot-starter-web dependency.</p>
  
  <p>Here is my controller showing the problem:</p>
  
  <pre class="lang-java prettyprint-override"><code>@PostMapping("/set_item")
  public void setItem(HttpSession session, @RequestParam String item) {
      System.out.println("Session Id " + session.getId());
      System.out.println("Item " + item);
      session.setAttribute("item", item);
      System.out.println("Session Item " + session.getAttribute("item"));
  }
  
  @GetMapping("/get_item")
  public Object getItem(HttpSession session) {
      System.out.println("Session Id " + session.getId());
      System.out.println("Session Attribute " + 
      session.getAttribute("item"));
      return session.getAttribute("item");
  }
  </code></pre>
  
  <p>When I make a request using POSTMAN on "<a href="http://localhost:8181/set_item?item=Banana" rel="nofollow noreferrer">http://localhost:8181/set_item?item=Banana</a>"
  what I get in the console is </p>
  
  <pre><code>Session Id 424dda79-f7b1-4818-8bcc-d371b4a1b7d5
  Item Banana
  Session Item Banana
  </code></pre>
  
  <p>So as we can see the attribute is set correctly.</p>
  
  <p>And my console log when I do a GET request on "<a href="http://localhost:8181/get_item" rel="nofollow noreferrer">http://localhost:8181/get_item</a>"</p>
  
  <pre><code>Session Id e04f0de2-d7d2-4827-9652-3f6232b27c3f
  Session Attribute null
  </code></pre>
  
  <p>So, a new instance is created.</p>
  
  <p>Thank you in advance.</p>