I want to create a new mule flow in runtime based on a flow-template. I found that Java module in mule 4 may help me with this, so in my main flow, I tried to invoke Java instance method:
<http:listener doc:name="Listener" doc:id="5b0f79ff-1a60-4c1a-bc9d-fbe350f4e595" config-ref="HTTP_Listener_config" path="/producer"/>
<java:new doc:name="New DynamicProducerFlowGenerator" doc:id="6c8cf087-0601-4b89-9d24-16650b9a6e6f" class="DynamicProducerFlowGenerator" constructor="DynamicProducerFlowGenerator()" target="DynamicProducerFlowGenerator"/>
<java:invoke doc:name="Invoke" doc:id="d5258c18-74e8-4c86-a0ae-758ad41d1b32" instance="#[vars.DynamicProducerFlowGenerator]" class="DynamicProducerFlowGenerator" method="initialise()"/>
To invoke this method, I created a Java class called DynamicProducerFlowGenerator, this is my Java code:
public class DynamicProducerFlowGenerator {
public DynamicProducerFlowGenerator() {
}
public void initialise() {
MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
ConfigurationBuilder builder = new SpringXmlConfigurationBuilder("dynamic-producer-flow-template.xml");
MuleContext muleContext = muleContextFactory.createMuleContext();
builder.configure(muleContext);
muleContext.start();
}
}
However, when I tried to run this, I always got a error:
Message : Invocation of Method 'initialise()' from Class 'DynamicProducerFlowGenerator' without any argument resulted in an error.
Cause: org.mule.api.MuleRuntimeException - Couldn't find config via SPI mechanism. Corrupted Mule core jar?
I think the problem lies in this line of code
"MuleContext muleContext = muleContextFactory.createMuleContext();"
But I do not know how to solve it. This is my some of dependencies in pom.xml:
<dependency>
<groupId>org.mule.tools.devkit</groupId>
<artifactId>mule-devkit-annotations</artifactId>
<version>3.9.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mule</groupId>
<artifactId>mule-core</artifactId>
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>org.mule.module</groupId>
<artifactId>mule-java-module</artifactId>
<version>1.2.6</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-spring-config</artifactId>
<version>3.9.0</version>
Could anyone help me with this? Is there another way that I can use to create a new flow in runtime in mule 4?
Thank you in advance