ITeye博客

使用spring读取properties文件

zus · 2015-12-24 14:10 · spring · 企业架构 · Markdown

spring可以在配置文件中使用properties文件中配置的项,但是有时候我们也需要直接通过代码去存取配置文件中的项,该怎么做呢?

其实也很简单,spring提供了PropertiesLoaderUtils类,此类可以方便的载入properties配置文件,如下实例代码:

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;


Resource resource = new ClassPathResource("/my.properties");
Properties props = PropertiesLoaderUtils.loadProperties(resource);

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。