java读取resource下的配置文件
代码如下:
@Test
public void getInfo(){
InputStream in = this.getClass().getResourceAsStream("/application.yml");
Properties properties = new Properties();
try {
properties.load(in);
} catch (IOException e) {
e.printStackTrace();
}
String port = properties.getProperty("port");
String size = properties.getProperty("max-http-header-size");
int intport = Integer.parseInt(port);
int intsize = Integer.parseInt(size);
System.out.println("端口号" + intport);
System.out.println("最大尺寸" + intsize);
}
配置文件:
测试结果:
