문제

I have a POJO component which basically contains some Java classes. At this point I have some settings hardcoded (such as some credentials) that I would like to configure somehow in the flow via the Studio GUI.

Is is possible to store somehow in the flow some settings that can easily be read by my POJO component?

도움이 되었습니까?

해결책

I see two options:

  1. Setting the credentials as System Properties using -M-Dproperty in command line and retrieving it from your POJO using java.lang.System.getProperty("property")
  2. Configuring the credentials in a .properties file and retrieve them from the Property placeholder from the Mule Registry. You can implement org.mule.api.context.MuleContextAware perhaps, or a Lookup annotation.

Also read this

다른 팁

I ended up using this solution.

  1. Storing configuration as global properties:
<global-property name="mysystem.username" value="JSmith" doc:name="Global Property"/>
  1. Using the @Lookup annotation in the POJO to read it:

    import org.mule.api.MuleContext;
    import org.mule.api.annotations.expressions.Lookup;
    
    
    public class MulePOJO {
    
    /* http://www.mulesoft.org/documentation/display/current/Lookup+Annotation*/
    @Lookup
    private MuleContext muleContext;
    
    public String singleArgumentMethod(String x)
    {
        String value = muleContext.getRegistry().get("mysystem.username");
    
        return  x;
    }
    }
    
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top