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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:33:48+00:00 2026-06-05T05:33:48+00:00

I am trying to implement FactoryBean. Here is my code: public class SkilledEmployee extends

  • 0

I am trying to implement FactoryBean. Here is my code:

public class SkilledEmployee extends AbstractFactoryBean<Employee> {

    private Employee emp;
    private Skill skill;

    public SkilledEmployee(Employee emp, Skill skill) {
        this.emp = emp;
        this.skill = skill;
    }

    public Class<Employee> getObjectType() {
        return Employee.class;
    }

    protected Employee createInstance() throws Exception {
            Employee emp1 = new Employee(emp);
        emp1.addSkill(skill);
        return emp1;
    }

    public boolean isSingleton() {
        return true;
    }

}

And here is how I declared my beans:

<bean id="skilledEmployee1" class="com.pramati.spring.SkilledEmployee">
                <constructor-arg ref="subordinate3"/>
                <constructor-arg ref="singing"/>
            </bean>
            <bean id="skilledEmployee2" class="com.pramati.spring.SkilledEmployee">
                <constructor-arg ref="subordinate2"/>
                <constructor-arg ref="singing"/>
            </bean>

When I get these beans from context, I see that I am getting different beans though I declared the object to be singleton.

I am trying to understand FactoryBean and I know that this is not a valid usecase and it’s a blunder in design. But I wanted to know why it is behaving like this? Can someone please explain?

  • 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-05T05:33:51+00:00Added an answer on June 5, 2026 at 5:33 am

    These are two disctinct beans because you declared them separately. Simpler example:

    <bean id="foo1" class="com.example.Foo"/>
    <bean id="foo2" class="com.example.Foo"/>
    

    Here we declared two singleton beans, foo1 and foo2. If you fetch them from Spring, you will get two different objects. However if you fetch them again, you’ll get the same object.

    Similarilly in your case: skilledEmployee1 and skilledEmployee2 are two distinct, singleton beans. If you get them from the context again, you’ll receive the same instance – as expected.

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

Sidebar

Related Questions

I don't know what this is called but here goes. public class Person {
SetFocus I'm trying implement the above Se Focus code in a Class Library that
Trying to implement this gallery on my website. http://coffeescripter.com/code/ad-gallery/ It is noted in the
Im trying to implement this code: http://wcf.codeplex.com/wikipage?title=Getting%20started:%20Building%20a%20simple%20web%20api and want to add it to my
Iam trying to implement a simple JMS(traditional not using springs) code in eclipse using
Found a really nice code for Accordion nav and am trying implement on our
Trying to implement the decorator pattern in C# from the code in the Head
Trying to implement the excellent jQuery bidirectional infite scroll as explained here: http://www.bennadel.com/blog/1803-Creating-A-Bidirectional-Infinite-Scroll-Page-With-jQuery-And-ColdFusion.htm For
Trying to implement an autocomplete based on this It looks like it's very straight
I have this weird kind of error. I am trying implement basic Euclidean algorithm

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.