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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:12:04+00:00 2026-05-29T12:12:04+00:00

I have a session-scoped bean in Spring that is set within the web context.

  • 0

I have a session-scoped bean in Spring that is set within the web context. I have a task that runs as a Callable, and I need access to this bean from within that thread. How should I accomplish this? If I simply attempt autowiring the bean I get the error message:

Scope ‘session’ is not active for the current thread

The session-scoped bean I am injecting looks like this:

<bean id="userInfo" class="com.company.web.UserInfoBean" scope="session">
    <aop:scoped-proxy />
</bean>

And the class I am trying to inject it into looks like this:

@Component
@Scope( value = "thread", proxyMode = ScopedProxyMode.TARGET_CLASS )
public class GenerateExportThread implements Callable<String> {
  ...
  // this class contains an @Autowired UserInfoBean
  @Autowired
  private ISubmissionDao submissionDao;
  ...
}

Lastly, the Callable is being started up like this:

@Autowired
private GenerateExportThread generateExportThread;

@Autowired
private AsyncTaskExecutor taskExecutor;

public void myMethod() {
...
    Future<String> future = taskExecutor.submit( new ThreadScopeCallable<String>( generateExportThread ) );
...
}

The ISubmissionDao implementation gets injected correctly, but not its UserInfoBean because that bean is session-scoped. I am okay with doing some manual code work if necessary to copy the object from one session into another at thread startup time (if this makes sense) but I just don’t know how to go about doing this. Any tips are appreciated. Thanks!

  • 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-29T12:12:05+00:00Added an answer on May 29, 2026 at 12:12 pm

    Do manual injection:

    Your thread-scoped bean:

    @Component
    @Scope( value = "thread", proxyMode = ScopedProxyMode.TARGET_CLASS )
    public class GenerateExportThread implements Callable<String> {
        ...
        // this class contains an @Autowired UserInfoBean
        private ISubmissionDao submissionDao;
    
        public void setSubmissionDao(ISubmissionDao submissionDao) {
            this.submissionDao = submissionDao;
        }
        ...
    }
    

    On your request thread:

    ...
    @Autowired  // This should work as a request has an implicit session
    private ISubmissionDao submissionDao;
    
    @Autowired  // This should also work: the request thread should have a thread-scoped exportThread
    private GenerateExportThread generateExportThread;
    
    ...
    generateExportThread.setSubmissionDao(submissionDao);
    String result = generateExportThread.call(); // Or whatever you use to run this thread
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application written in JSF2 that uses Spring. I need to
Assume I have a session scoped bean with object references in it, where the
i have a strange behaviour i'm seeing that if the user access to session
I have a session scoped managed bean with name 'usermanager'. i want to store
I have already one session scoped CDI bean, which keeps currently logged in user
I have the following confguration in my JSF Spring application: <bean id=userSessionBean class=com.vanilla.beans.UserSessionBean scope=session>
I have a Spring Web MVC application where i need to use an external
I have a session class that needs to store session information in a MySQL
I am currently in C# and I have set Session variables on each page.
Weired problem! ASP.NET Session expires instantly. In my web.config I have this session settings:

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.