看好多都写的使用下面获取properties文件:
<span style="font-size:18px;"></span><pre name="code" class="java" style="text-align: justify;"><span style="font-size:18px;">InputStream in = <span style="font-family: Arial, Helvetica, sans-serif;">Object.class.getResourceAsStream("/name.properties");</span></span>
但是在Java Web中返回的是null
可以使用下面代码获取到properties文件:
<span style="font-size:18px;">Properties prop = new Properties();
InputStream in = this.getClass().getResourceAsStream("/name.properties");
if(in != null){
prop.load(in);
if(!prop.isEmpty()){
configEntity.setBrokerHost(prop.getProperty("name"));
}
} else {
logger.info("未找到资源文件");
}</span>