org.springframework.core.io.ResourceLoader 类读取配置文件 ( 配置文件需放在类路径下)
public class loadeProperties(){
private static ResourceLoader resourceLoader = new DefaultResourceLoader();
//参数是 文件名字的字符串数组形式。
public static Properties loadProperties(String... resourcesPaths){
Properties props = new Properties();
for (String location : resourcesPaths) {
InputStream is = null;
try {
Resource resource = resourceLoader.getResource(location);
is = resource.getInputStream();
props.load(is);
} catch (IOException ex) {
// logger.info("Could not load properties from path:" + location + ", " + ex.getMessage());
} finally{
//IOUtils.closeQuietly(is);
}
}
return props;
}
public static void main(String arg[]){
//参数是 文件名字的字符串数组形式。
Properties property= loadeProperties.loadProperties(new String[] { "url.properties" });
}
}
spring resourceLoader 读取配置文件
最新推荐文章于 2025-06-23 14:44:48 发布