I have a User class:
@Component
@Scope("session")
public class User {
private String username;
}
And a Controller class:
@Controller
public class UserManager {
@Autowired
private User user;
@ModelAttribute("user")
private User createUser() {
return user;
}
@RequestMapping(value = "/user")
public String getUser(HttpServletRequest request) {
Random r = new Random();
user.setUsername(new Double(r.nextDouble()).toString());
request.getSession().invalidate();
request.getSession(true);
return "user";
}
}
I invalidate the session so that the next time i got to /users, I get another user. I'm expecting a different user because of user's session scope, but I get the same user. I checked in debug mode and it is the same object id in memory. My bean is declared as so:
<bean id="user" class="org.synchronica.domain.User">
<aop:scoped-proxy/>
</bean>
I'm new to spring, so I'm obviously doing something wrong. I want one instance of User for each session. How?