I have a User class:
@Component
@Scope(\"session\")
public class User {
private String username;
}
And a Controller class:
This is the expected behavior. When you tag a bean with <aop:scoped-proxy/>
a proxy is created for it. If there is an interface for the bean a java dynamic proxy is created else a CGLIB based proxy is created - in your case since your User class does not have a parent class/interface a CGLIB based proxy will be created for you.
Now the catch is that this proxy is what will be injected into all your classes, that is the reason why you are seeing only 1 instance(of the proxy essentially), the proxy knows how to manage the scope though - As long as you go through the methods of your class, so in your case if you go through getter and setter calls to get to the properties of your User class, you should see values appropriate to the session reflected.