Using StaticApplicationContext for managing beans dynamically
===

I am looking for a way of creating dynamiclly sessions beans with states. 

I am connecting via external protocol to another machine. 

Each time a I recieve a request I am willing to create programmatic a new spring bean which will work asynchronously(Listen to jms events, do some actions, etc). 

That bean will be configured with dynamic parameters(coming from the request). 

I need a way of creating/destroying/configuring those dynamic beans.

I got a hint about using StaticApplicationContext. for example:

    ApplicationContext context = ApplicationContextSingleton.getApplicationContext();
        		innerContext = new StaticApplicationContext(context);

and this is how ill create and configure the beans dynamically:

   

     public void createBean(String beanName, String beanParam)
        	{
        		System.out.println("beanName=" + beanName + " beanParam=" + beanParam);
        		
        		innerContext.registerSingleton(beanName, FixSessionBean.class);
        		configureBean(innerContext, beanName, beanParam);
        
        	}

so basically all dynamic beans will be under innerContext.

and in order to configure bean ill use it this way:

    public void configureBean(ApplicationContext innerContext, String beanName, String beanParam)
    	{
    		FixSessionBean fixSessionBean = (FixSessionBean) innerContext.getBean(beanName);
    		fixSessionBean.setMyProperty("32");
    	}

so In order to retrieve bean to do some actions I use this:

    FixSessionBean fixSessionBean = (FixSessionBean) innerContext.getBean(beanName);

this is my applicationXML:

    <bean id="FixSessionBean" class="com.fixgw.beans.FixSessionBean" />

two questions:

1. using this Technic might harm performances/memory leaks(coz I over use innerContext.getBean)?

2. If you have idea for a better Technic to achieve my target your more then welcome.

thanks,
ray.
