Reputation: 1289
I use some classes along the flow
in Mule
.
In one of those Java classes
, I set an object with some values.
At the end I want to call to that object with the values setted.
I have a spring bean
with the class:
<spring:bean id="personObject" class="object.Person" />
Then, at the end, in my Java code I use:
@Override
public Object onCall(MuleEventContext arg0) throws Exception {
Person person = arg0.getMuleContext().getRegistry().lookupObject("personObject");
}
But person
returns all values with null.
All fields from Person class have setters and getters.
What I'm doing wrong?
Upvotes: 0
Views: 164
Reputation: 367
I think problem here is , Spring bean contains the initial state of Person class when the application is deployed and it's not refreshed after that.
You can try in other way, instead of creating spring bean in the global elements, you can add the person object to registry from java code after you done with setting up data like below (you should return the Mule eventcontext from this class).
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
Person per = new Person();
per.setName("Mulesoft");
eventContext.getMuleContext().getRegistry().registerObject("personObject", per);
return eventContext;
}
From the other java classes in the flow, you can read the person Object values like
@Override
public Object onCall(MuleEventContext eventContext) throws Exception {
Person person = eventContext.getMuleContext().getRegistry().lookupObject("personObject");
System.out.println("Name is :"+person.getName());
return null;
}
Give a try if you like this approach.
Upvotes: 1