Announcement Announcement Module
Collapse
No announcement yet.
Using GenericBeanDefinition to create MethodInvokingFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using GenericBeanDefinition to create MethodInvokingFactoryBean

    Hi,
    I was trying to dynamically invoke method on a dynamically created bean, actually have to do this for a configurable set of beans in a certain order. I was stuck where I had to pass the "arguments" as a property. Following is the code -

    Code:
    		BeanDefinitionRegistry registry = ((BeanDefinitionRegistry )factory);  
    		      
    		GenericBeanDefinition beanDefinition = new GenericBeanDefinition();  
    		beanDefinition.setBeanClass(org.springframework.beans.factory.config.MethodInvokingFactoryBean.class);  
    		beanDefinition.setLazyInit(false);  
    		beanDefinition.setAbstract(false);  
    		beanDefinition.setAutowireCandidate(true);
       
    		MutablePropertyValues values = new MutablePropertyValues();
    		values.addPropertyValue("targetObject", new RuntimeBeanReference("dsImpl"));
    		values.addPropertyValue("targetMethod", "getBookData");
    		values.addPropertyValue("arguments",/* ??? */ ); // how do I pass this?
    
    		beanDefinition.setPropertyValues(values);
    
          
    		registry.registerBeanDefinition("bookData",beanDefinition);
    Any suggestions will be of great help.

    Thanks,
    Dwipin.

  • #2
    Hi Dwipin,

    Do you mean constructor arguments ?

    Originally posted by dwipin View Post
    I was trying to dynamically invoke method on a dynamically created bean, actually have to do this for a configurable set of beans in a certain order. I was stuck where I had to pass the "arguments" as a property.

    Code:
    		values.addPropertyValue("arguments",/* ??? */ ); // how do I pass this?
    If it is the case, you may try:

    Code:
    ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues() {
      {
        addGenericArgumentValue(...);
      }
    };
    beanDefinition.setConstructorArgumentValues(constructorArgumentValues);
    Philippe

    Comment

    Working...
    X