简体   繁体   English

在Mule中将设置添加到POJO组件

[英]Adding settings to a POJO component in Mule

I have a POJO component which basically contains some Java classes. 我有一个POJO组件,该组件基本上包含一些Java类。 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. 此时,我已经通过Studio GUI在流程中以某种方式对一些设置进行了硬编码(例如某些凭据)。

Is is possible to store somehow in the flow some settings that can easily be read by my POJO component? 是否可以以某种方式在流程中存储一些可以由我的POJO组件轻松读取的设置?

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") 在命令行中使用-M-Dproperty将凭据设置为“系统属性”,然后使用java.lang.System.getProperty(“ property”)从POJO检索凭据
  2. Configuring the credentials in a .properties file and retrieve them from the Property placeholder from the Mule Registry. 在.properties文件中配置凭据,然后从Mule注册表的Property占位符中检索它们。 You can implement org.mule.api.context.MuleContextAware perhaps, or a Lookup annotation . 您可以实现org.mule.api.context.MuleContextAware或Lookup批注

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: 在POJO中使用@Lookup批注读取它:

     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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM