呦可以宣佈在你的騾流量以下,你不需要的Spring bean爲: -
<context:property-placeholder location="classpath:yourpropertFileName.properties"/>
將只讀服務器啓動後一次/重啓
UPDATE
假設你有一個屬性文件命名爲yourpropertFileName.properties
和你定義了以下項和值在它: -
message1=This is message1 value
message2=This is message2 value
現在你可以在騾流量使用它像以下內容: -
<logger message="${message1}" level="INFO" />
<logger message="${message2}" level="INFO" />
正如你可以看到我已經從屬性讀取鍵和值文件和Mule的配置文件,把它用在記錄器。 。同樣的方式,你可以使用鑰匙從性能在任何騾子組件文件要
更新: - 下面是一個簡單的Java類,從屬性值讀取文件。您可以按照您的要求修改: -
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractMessageTransformer;
public class SampleJavaClass extends AbstractMessageTransformer {
Properties prop = new Properties(); //Creating property file object read File attachment path from property file
InputStream input = null; // To read property file path
@Override
public Object transformMessage(MuleMessage message, String outputEncoding)
throws TransformerException {
try {
input = getClass().getResourceAsStream("yourpropertFileName.properties"); // Property file path in classpath
prop.load(input); // get and load the property file
String msg1=prop.getProperty("message1");
String msg2=prop.getProperty("message2");
System.out.println("Key1 from Prop file "+msg1);
System.out.println("Key2 from Prop file "+msg2);
} catch (IOException e)
{
e.printStackTrace();
}
return message;
}
}
爲了澄清,Mule在內部使用了Spring框架。 Spring用於加載Mule配置文件,因此您可以直接添加上下文名稱空間。 – 2014-11-01 21:17:38
@Anirban:謝謝你的回覆。我如何在我的Java代碼中使用這個屬性文件的關鍵字。請幫忙。 – SonuR 2014-11-04 20:04:12
我已經更新了我的答案。如果您覺得有用,請接受答案 – 2014-11-05 08:12:21