【发布时间】:2015-01-08 19:29:28
【问题描述】:
我正在尝试使用 PropertyReader 类从 java spring 中的 test.properties 文件中获取我的信息(端口号、主机名等),但我对如何去做这件事感到很困惑,因为似乎有一个百万种不同的方式(资源包等)......我将不胜感激任何输入!这是我的代码的样子。哦,名称与属性文件中的名称相同。
@Configuration
@PropertySource("classpath:test.properties")
public class PropertyReader {
private Environment environment;
String portNumber;
String hostName;
String subjectName;
String myUrl;
String portProtocol;
String hostProtocol;
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
public PropertyReader(String propertyFile) throws IOException {...}
我已经添加了
<context:property-placeholder location="classpath:test.properties" />
我的上下文。但不确定如何获取环境信息。getProperty 似乎没有被识别为函数......
【问题讨论】:
标签: java spring properties-file