`

使用spring读取properties文件

阅读更多

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);

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics