for example, if my link.properties file contains phone= http://localhost:8080/Validation/phone placed in cofig folder , how the value phone be accessed in a mediator(proxy mediator).
您可以使用类调解器读取属性文件并从那里加载值。
Considering your properties file should be located in the <project name>/src/main/resources directory, you can use this method for reading property files:
import import java.util.Properties;
import java.net.URL;
Properties readPropertiesFile() {
// Looks for "application.properties" in "<project name>/src/main/resources"
URL fileUrl = Thread.currentThread().getContextClassLoader().getResource("application.properties");
Properties applicationProperties = new Properties();
try {
// Load properties from file
applicationProperties.load(fileUrl.openStream());
} catch (Exception e) {
// File not found, invalid permissions, usual file handling stuff...
e.printStackTrace();
return null;
}
return applicationProperties;
}
You can read the property like this:
Properties applicationProperties = readPropertiesFile();
if (applicationProperties == null) {
// null handling
}
String yourProperty = (String) applicationProperties.get("your.property.name");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.