Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:10:29+00:00 2026-06-14T20:10:29+00:00

I have a User class: @Component @Scope(session) public class User { private String username;

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:10:30+00:00Added an answer on June 14, 2026 at 8:10 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class: @Component @Scope(session) @Entity @Table(name = users) public class User {
I have a User and School Class, public class User { private Long id;
I have a class User that looks like this: class User { private: char*
I have made a small custom view component: public class ActionBar extends RelativeLayout {
It seems impossible to me to have a natural-id in a component. public class
i have a User class with a field for the e-mail-address and a password.
Alright so here is the question. I have a user class which contains a
I have a user and nested profile class as follows: class User < ActiveRecord::Base
i have a class User which extends Ebean Model. And i defined a dbfile
I have a class User with one field called birthDate which is a java.sql.Date

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.