1.首先在配置中加载配置文件
<context:property-placeholder location="WEB-INF/config.properties" ignore-unresolvable="true"/>
2.在配置文件中引种时可以直接用 ${配置key名称},列如:
<property name="nameServer" value="${rocketmq.server.name}"/>
3.在代码中引用 System.getProperty(“配置key名称”),列如:
System.getProperty("rocketmq.namesrv.domain")
示列:release.properties
tourist.android.appUrl=www.baidu.com
tourist.android.release=1.0.3
tourist.android.isEnforce=true
guide.android.appUrl=www.baidu.com
guide.android.release=1.0.3
guide.android.isEnforce=true
java 代码
Resource resource = new ClassPathResource("/release.properties");
Properties properties= PropertiesLoaderUtils.loadProperties(resource);
String touristAndroidRelease = properties.getProperty("tourist.android.release");
String touristAndroidUrl = properties.getProperty("tourist.android.appUrl");
String touristAndroidIsEnforce = properties.getProperty("tourist.android.isEnforce");
本文详细介绍了如何在配置中加载配置文件,并通过属性占位符进行引用,同时提供了示例代码来展示如何在Java环境中读取并使用配置文件中的属性。
225

被折叠的 条评论
为什么被折叠?



