Reputation: 1
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";
}
}
Upvotes: 0
Views: 137