ITeye博客

Spring使用程序方式读取properties文件

peihong-ph · 2014-07-03 10:37 · 技术类 · 编程语言 · Spring · Markdown

Spring使用程序方式读取properties文件 在spring中可以通过下面的方式将配置文件中的项注入到配置中 classpath*:application.properties 但是这样的注入没有办法通过程序来访问properties文件中的内容,spring还提供了 org.springframework.core.io.support.PropertiesLoaderUtils类可以方便的载入配置文件,如下两行代码: Resource resource = new ClassPathResource("/application.properties"); Properties props = PropertiesLoaderUtils.loadProperties(resource); 需要引用下面的类: import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PropertiesLoaderUtils;

评论(0)

暂无评论。

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