一、读取配置文件
错误代码
Properties properties = new Properties();
FileInputStream fileInputStream = new FileInputStream();
properties.load(fileInputStream);
需要target文件,在服务器上以war运行时出问题
正确代码
Properties properties = new Properties();
ClassPathResource classPathResource = new ClassPathResource("mismatch-urls.properties");
InputStream inputStream = classPathResource.getInputStream();
properties.load(inputStream);
代码解读
再进去
获取当前线程的类加载器,从而获取到了我们的资源文件