I have a small Spring MVC application, where a few classes depends on User object.
I'd like to declare it as @Component, so i can access this bean from any place with @Autowired annotation.
@Component
public class MyUser implements User {
// private fields
// getters and setters
public void fillByName(String username) {
userDao.select(username);
}
}
Obviously, User object should be unique for each user. I use Spring Security, so there is username in my SecurityContextHolder, which i can use to initialize User object.
What is the best practice for the initialization? Should i declare it like session scoped bean? Or should i keep it as singleton class and just update all fields for each request? Or maybe i should create a new User object from the Controller class for each request?