【发布时间】:2017-10-28 13:59:20
【问题描述】:
在我的 maven 项目中,我有一个这样的静态代码:
static {
int address = xxx;
int port = xxx;
}
我想用一个属性文件来定义变量,属性文件在我项目的resources目录下,但是我尝试了很多方法将这个属性文件导入到静态代码文件中,比如如:
Properties prop = new Properties();
prop.load(RedisPool.class.getClassLoader().getResourceAsStream("config.properties"));
但它不起作用。
【问题讨论】:
-
为什么不在你的代码中使用属性...写一个类当然你应该使用
getResourceAsStream("/config.properties")...如果你的config.properties文件位于src/main/resources...
标签: java maven properties static