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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:12:26+00:00 2026-05-13T07:12:26+00:00

I want to inject currentUser instance in HomeController class. so for every request, HomeController

  • 0

I want to inject currentUser instance in HomeController class. so for every request, HomeController will have currentUser object.

My configuration:

<bean id="homeController" class="com.xxxxx.actions.HomeController">
    <property name="serviceExecutor" ref="serviceExecutorApi"/>
    <property name="currentUser" ref="currentUser"/>
</bean>

<bean id="userProviderFactoryBean" class="com.xxxxx.UserProvider">
    <property name="userDao" ref="userDao"/>
</bean>

<bean id="currentUser" factory-bean="userProviderFactoryBean" scope="session">
    <aop:scoped-proxy/>
</bean>

But I am getting following error.

Caused by: java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.currentUser': Target type could not be determined at the time of proxy creation.
        at org.springframework.aop.scope.ScopedProxyFactoryBean.setBeanFactory(ScopedProxyFactoryBean.java:94)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1350)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)

What is the problem? and Is there any better/simple alternative?

Cheers.

  • 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-13T07:12:27+00:00Added an answer on May 13, 2026 at 7:12 am

    With scoped-proxies, Spring still needs to know the type of the bean when the context is initialized, and in this case it’s failing to do so. You need to try and give it more information.

    I notice that you’re only specifying factory-bean in your definition of currentUser, with no factory-method specified. I’m actually rather surprised that that’s a valid definition, since the two are normally used together. So try adding the factory-method attribute to currentUser, which specifies the method on userProviderFactoryBean which creates the user bean. That method needs to have a return type of your User class, which Spring will use to infer the type of currentUser.


    Edit: OK, after your comment below, it seems you’ve misunderstood how to use factory beans in Spring. When you have a bean of type FactoryBean, you don’t need to use the factory-bean attribute as well. So instead of this:

    <bean id="userProviderFactoryBean" class="com.xxxxx.UserProvider">
        <property name="userDao" ref="userDao"/>
    </bean>
    
    <bean id="currentUser" factory-bean="userProviderFactoryBean" scope="session">
        <aop:scoped-proxy/>
    </bean>
    

    You just need this:

    <bean id="currentUser" class="com.xxxxx.UserProvider" scope="session">
        <aop:scoped-proxy/>
        <property name="userDao" ref="userDao"/>
    </bean>
    

    Here, UserProvider is a FactoryBean, and Spring knows how to handle that. The end result will be that the currentUser bean will be whatever UserProvider generates, rather than an instance of UserProvider itself.

    The factory-bean attribute is used when the factory is not a FactoryBean implementation, but just a POJO, and it allows you to tell Spring explicitly how to use the factory. But because you’re using FactoryBean, there’s no need for this attribute.

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

Sidebar

Ask A Question

Stats

  • Questions 515k
  • Answers 515k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You're going to want to use the ContentValues to achieve… May 16, 2026 at 6:24 pm
  • Editorial Team
    Editorial Team added an answer OPENQUERY is definitely a way to do it; what issues… May 16, 2026 at 6:24 pm
  • Editorial Team
    Editorial Team added an answer you can use - alter table <mytable> add ident INT… May 16, 2026 at 6:24 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a bean that i want to inject with a named list using
I want to inject the following line into the top of every method of
I want to inject a plain java object using Spring programmatically without using any
I have managed bean/backing bean and I inject there (with @EJB) session bean. Now
I want to inject some Json into the Html page returned by the server?
I want to inject a confirmation dialog to allow the user to cancel the
I want to inject one additional variable into the context of a view that
I want to inject a connection string into my repository but ideally, I want
I just want to inject some design patterns into my Java code, but I
I want to inject a css file located on the skin folder in a

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.