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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:53:37+00:00 2026-05-23T12:53:37+00:00

I want to create a bean that will act as a provider. I will

  • 0

I want to create a bean that will act as a provider.
I will give it the class that it should return and the list of properties that I should set before returning it.

so basically it looks like this:

<bean id="somethingFactory" class="foo.bar.SomethingFactory">
  <property name="implClass" value="foo.bar.SomehtingImpl" />
  <property name="properties">
    <props>
       <prop key="prop1">prop1Value</prop>
       <prop key="prop2">prop2Value</prop>
     </props>
   </property>
</bean>

The “SomethingFactory” has a provide() method that will return an instance of “SomehtingImpl”.

The question is how can I use Spring to do it?

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

    Make SomethingFactory a FactoryBean, extend AbstractFactoryBean and use a BeanWrapper to populate the properties from the input parameters.

    Here’s a sample implementation:

    public class ServiceFactoryBean<T> extends AbstractFactoryBean<T> {
    
        private Class<T> serviceType;
        private Class<? extends T> implementationClass;
        private Map<String, Object> beanProperties;
    
    
        @Override
        public void afterPropertiesSet() {
            if (serviceType == null || implementationClass == null
                    || !serviceType.isAssignableFrom(implementationClass)) {
                throw new IllegalStateException();
            }
        }
    
        @Override
        public Class<?> getObjectType() {
            return serviceType;
        }
    
        public void setBeanProperties(final Map<String, Object> beanProperties) {
            this.beanProperties = beanProperties;
        }
    
        public void setImplementationClass(
            final Class<? extends T> implementationClass) {
            this.implementationClass = implementationClass;
        }
    
        public void setServiceType(final Class<T> serviceType) {
            this.serviceType = serviceType;
        }
    
        @Override
        protected T createInstance() throws Exception {
            final T instance = implementationClass.newInstance();
            if (beanProperties != null && !beanProperties.isEmpty()) {
                final BeanWrapper wrapper = new BeanWrapperImpl(instance);
                wrapper.setPropertyValues(beanProperties);
            }
            return instance;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a class that exends Comparator. This comparator will compare two
I have a class which will have a list of commands that it must
I have written a PropertyUtils class (from internet), which will load the Properties <bean
I want to create a JSP page or servlet that will work in 2
I want to dynamically create controls in my bean. I am using JSF 2.0
I want to dynamically create object of HtmlDivElement in my jsf managed bean and
I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that
I want create module which update list of usb devices automatically (not only mass
I want to create a Producer that makes it possible to inject a java.util.ResourceBundle

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.