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 3797758
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:27:26+00:00 2026-05-19T13:27:26+00:00

I have an old project that I need to integrate with Spring 2.5.x (3.0

  • 0

I have an old project that I need to integrate with Spring 2.5.x (3.0 is not possible).

I have created a bean, that have to initializate its field userSession by itself:

public class SomeBean {
    UserSession userSession;

    @PostContrust
    public void init() {
        HttpSession session = WebContext.current().getSession();
        userSession = (UserSession) session.getAttribute("userSession");
    }
}

Is it possible to write some kind of autowiring handler that will resolve userSession and pass it for autowiring to Spring, so my bean looks just like:

public class SomeBean {
    @Autowire UserSession userSession;
}

and the handler like:

public class AutowireHanlder {
    public boolean isCandidate(Class<?> type) {
        return type.equals(UserSession.class);
    }

    public Object resolve(Class<?> type) {
        HttpSession session = WebContext.current().getSession();
        return (UserSession) session.getAttribute("userSession");
    }
}
  • 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-05-19T13:27:26+00:00Added an answer on May 19, 2026 at 1:27 pm

    I would do this using a session-scoped FactoryBean:

    public class UserSessionFactoryBean extends AbstractFactoryBean<UserSession> {
    
        @Override
        public Class<?> getObjectType() {
            return UserSession.class;
        }
    
        @Override
        protected UserSession createInstance() throws Exception {
            HttpSession session = WebContext.current().getSession();
            return (UserSession) session.getAttribute("userSession");   
        }
    
    }
    

    Define UserSessionFactoryBean as a bean:

    <bean scope="session" class="com.xyz.UserSessionFactoryBean"/>
    

    … and then you should then be able to autowire UserSession into any other bean.

    The complexity here is that UserSessionFactoryBean has to be session-scoped (see docs on bean scopes), since it must return a new value for each HttpSession. This means that any bean it is autowired into must also be session-scoped, otherwise it’ll fail. You can get around this restriction using scoped-proxies.

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

Sidebar

Related Questions

So I have a project that uses the old-style encodeObject:/decodeObject NSCoder serialization. I need
I have been tasked with updating a old project that I did not write.
1) I have old project that I need to modify. I need to add
I have an old project that is mixed C and C++. It makes extensive
I have a very old project that includes the source from another project directly,
I have an old project at our company that uses shell scripting a lot.
I have an old EJB (2.1) project that uses xdoclet (1.2.3) to generate the
I have an old c++ project compiled with VC6. I need to statically link
I have an old VC 6.0 project with lots of C files. I need
I have 2 applications. App1 is some old selfmade php project, not using Zend.

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.