Tsukeawase 1013
Tsukeawase 1013

Reputation: 1

Spring Boot2.0 - @SessonScope cannot be updated and is not reflected in HttpSession

In Spring Boot1.5, it was possible to update the instance with @SessionScope. However, when Spring Boot 2.0 is used, the value is not updated and it remains null.

Session-scoped component:

@Data
@SessionScope
public class UserDto {
  private String firstName;
  private String lastName;
}

Controller:

@Controller
public class GreetingController {

  @Autowired
  UserDto userInfo;

  @RequestMapping("/greeting")

  public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
      model.addAttribute("name", name);
      userInfo.setFirstName("John");
      userInfo.setLastName("Smith");
      /**
      * There was null value in Spring Boot 2.0. 
      * In Spring Boot 1.5 it was "John".
      **/
      System.out.println(userInfo.getFirstName()); 
      return "greeting";
  }
}

debug result

Upvotes: 0

Views: 137

Answers (0)

Related Questions