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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:16:48+00:00 2026-06-17T09:16:48+00:00

I have a bean factory class as follows: public class BeanFactory { public static

  • 0

I have a bean factory class as follows:

public class BeanFactory {
public static BeanInterface getInstance(int id) {
    return new Bean(id);
    }
}

I want to use this class in spring container to get the instances of Instrument class, and have added a bean entry in applicationcontext.xml as follows:

<bean id="TestBean" class="com.test.beans.BeanFactory" factory-method="getInstance">
</bean>

But I am not able to find any way through which I can pass id to getInstance factory method.
Is there any way I can pass a parameter to this factory method?

EDIT: Consider the bean factory as scope=”prototype”. I want new instances of TestBean based on the value of ID.

  • 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-17T09:16:49+00:00Added an answer on June 17, 2026 at 9:16 am

    The rules are the same as if it was normal Spring constructor, i.e. you can use <contructor-arg value="..."/>

    From documentation

    Arguments to the static factory method are supplied via
    elements, exactly the same as if a constructor had
    actually been used. The type of the class being returned by the
    factory method does not have to be of the same type as the class that
    contains the static factory method, although in this example it is. An
    instance (non-static) factory method would be used in an essentially
    identical fashion (aside from the use of the factory-bean attribute
    instead of the class attribute), so details will not be discussed
    here.

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

Sidebar

Related Questions

I have a bean that describes my session factory. I only want to load
I have a stateless session bean which needs access to a factory class. Is
I have the following configuration in my applicationContext.xml: <bean class=org.springframework.beans.factory.config.PropertyPlaceholderConfigurer> <property name=locations> <list> <value>classpath:app.properties</value>
I have configured a Spring bean as follows to return a SecurityContext: <bean id=securityContext
I have the following code that works fine in my spring.xml... <beans:bean id=sessionFactory class=org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean>
I have a Java class which I'm using to instantiate multiple objects for use
i have a web.xml with these 2 servlet: <servlet> <servlet-name>ApplicationContextFactory</servlet-name> <servlet-class>com.bamboo.common.factory.ApplicationContextFactory</servlet-class> <load-on-startup>1</load-on-startup> </servlet> AND
I have a Unit testing problem where a class has a static variable which
I was trying to create factory class for my spring beans public interface MyBean
I have the following bean defined: <bean id=myBean class=com.me.myapp.Widget> <constructor-arg name=fizz value=null/> <constructor-arg name=buzz

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.