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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:41:06+00:00 2026-06-07T12:41:06+00:00

I am using Spring3.1 on standalone env. I set topic with jms templates this

  • 0

I am using Spring3.1 on standalone env.

I set topic with jms templates this way:

<bean id="mm1sessionsTopicSendingTemplate" class="org.springframework.jndi.JndiObjectFactoryBean"
    depends-on="jmsServerManagerImpl">
    <property name="jndiName">
        <value>/topic/mm1sessionsTopic</value>
    </property>
</bean>

For this topic I set MDB with DefaultMessageListenerContainer this way:

<bean id="mm1sessionDispatcherListener"
        class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="connectionFactory" />
        <property name="pubSubDomain" value="true" />
        <property name="concurrentConsumers" value="1" />
        <property name="destination" ref="mm1sessionsTopicSendingTemplate" />
        <property name="messageListener" ref="mm1SessionMDB" />
        <property name="sessionAcknowledgeModeName" value="AUTO_ACKNOWLEDGE" />
    </bean>

In this way I must set mm1SessionMDB in advanced via xml:

<bean id="mm1SessionMDB" class="com.mdb.SessionMDB">
        <property name="feedPropertiesDTO" ref="feedListenerMarketMaker1Properties" />

    </bean>

But I need my application to create the MDB instances programmaticly.

I mean i want to create the mdb’s via the code since each MDB will have different validation values for the messages that it will retrieve from the topic(via the feedPropertiesDTO)

basically I will have pool of MDB’s with the same logic but each one will have different properties. the creation time of the MDB’S must be on runtime.

is that possible?

thanks,
ray.

  • 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-07T12:41:10+00:00Added an answer on June 7, 2026 at 12:41 pm

    I think you can use factory method for instantating your MDB bean and use method

    Object getBean(String name, Object... args) throws BeansException;
    

    of the ApplicationContext in your code to instantiate bean frogramatically.

    As I know this method allows you to path argument to factory method.

    Here what is said in java doc for this method:

    Return an instance, which may be shared or independent, of the specified bean.

    Allows for specifying explicit constructor arguments / factory method
    arguments, overriding the specified default arguments (if any) in the
    bean definition.

    I have never used this approach but I think it colud work for your case.

    EDIT.

    Here is an example that demonstrates about what I’m talkin (It is very simple but I don’t have enough time to write more complicated).

    Suppose that have interface and two it’s implementations:

    public interface StringMakerInterface {
    
        // Just return simple String depending on concrete implementation.
        String returnDummyString();
    
    }
    
    public class StringMakerImpl1 implements StringMakerInterface {
    
        public String returnDummyString() {
            return "test bean impl 1";
        }
    
    
    }
    
    public class StringMakerImpl2 implements StringMakerInterface{
    
        public String returnDummyString() {
            return "test bean impl 2";
        }
    
    }
    

    And we have one class that uses concrete implementation of this interface and to which we should dinamically inject conctrete implementation:

    public class StringPrinter {
    
        private StringMakerInterface stringMaker;
    
        public StringMakerInterface getStringMaker() {
            return stringMaker;
        }
    
        public void setStringMaker(StringMakerInterface stringMaker) {
            this.stringMaker = stringMaker;
        }
    
        public StringPrinter() {
    
        }
    
        // Just print dummy string, returned by implementation
        public void printString() {
            System.out.println(stringMaker.returnDummyString());
        }
    }
    

    Here is configuration class for my example:

    @Configuration
    public class TestFactoryMethodConfig {
    
        @Bean(name = "stringMaker1")
        public StringMakerImpl1 stringMaker1() {
            return new StringMakerImpl1();
        }
    
        @Bean(name = "stringMaker2")
        public StringMakerImpl2 stringMaker2() {
            return new StringMakerImpl2();
        }
    
        @Bean(name = "stringPrinter")
        @Scope(value = "prototype")
        public StringPrinter stringPrinter(@Qualifier("stringMaker1") StringMakerInterface stringMaker) {
            StringPrinter instance = new StringPrinter();
            instance.setStringMaker(stringMaker);
    
            return instance;
        }
    }
    

    And here is a test case that demonstrates dinamically injection at the runtime:

    @RunWith(value = SpringJUnit4ClassRunner.class)
    @ContextConfiguration(classes={TestFactoryMethodConfig.class})
    public class TestFactoryMethod {
    
        @Autowired
        private ApplicationContext applicationContext;
    
        @Resource(name = "stringMaker1")
        private StringMakerInterface stringMaker1;
    
        @Resource(name = "stringMaker2")
        private StringMakerInterface stringMaker2;
    
        @Test
        public void testFactoryMethodUsage() {
    
            StringPrinter stringPrinter1 = (StringPrinter) applicationContext.getBean("stringPrinter", stringMaker1);
    
            StringPrinter stringPrinter2 = (StringPrinter) applicationContext.getBean("stringPrinter", stringMaker2);
    
            stringPrinter1.printString();
            stringPrinter2.printString();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Spring MVC, is there any way to factorize the org.springframework.ui.Model , in order
I am using Spring3.1 My application will have kind of bean-manager. That manager will
When using spring security, specifically with @notation; what is the proper way to access
I a working on a JSF2/Spring3/JPA2 project using facelets as view technology. javax.faces.DEFAULT_SUFFIX is
I'm trying to create a standalone app using JBoss Microcontainer for IoC and JBoss
I try to learn Spring. I am following this site http://www.roseindia.net/spring/spring3/spring-3-hello-world.shtml I tried one
Using: Spring 3.1.0.RELEASE, Spring Data MongoDB 1.0.0.RELEASE I have a document class defined like
I asked a question yesterday ( Using Spring in standalone apps ) on how
I'm having some issues with Jetty7 standalone and my spring web app using jsp/jstl/el.
I am using hsqldb standalone as my database. i have a hsqldb.jar(hsqldb-2.0.0) which i

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.