Search code examples
javaosgiblueprint-osgi

How to invoke a bean method in Apache Blueprint?


I have the following java classes

public class SecondClass
{
    //...
}

public class MyClass
{
    public void doSomething(SecondClass secondClass)
    {
        //...
    }
}

In blueprint I have something like the following

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

    <bean id="secondClass" class="foo.bar.SecondClass" />

    <bean id="myClass" class="foo.bar.MyClass" />

    <!-- How do I invoke myClass.doSomething(secondClass) ??? -->

</blueprint>

Someone knows how to call myClass.doSomething(secondClass) from inside Blueprint?


Solution

  • If I understand correctly (not being very familiar with the MethodInvokingFactoryBean myself) what you need is a factory method, ie. something like the following:

       <bean id="myClass" class="foo.bar.MyClass" 
             factory-method="doSomething">   
           <argument ref="secondClass"/>    
       </bean>
    

    You can find more details on how to use factories with blueprint in this guide (one of the most useful blueprint resources IMO)