pom中添加:
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/</directory>
<filtering>false</filtering>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
resource的filtering属性用来表示资源文件中的占位符是否需要被替换,true为需要替换。
在idea下直接运行:
Properties properties = new Properties();
InputStream in = PropertiesUtils.class.getClassLoader().getResourceAsStream("./application.properties");
properties.load(in);
maven 打包运行
Properties properties = new Properties();
InputStream in = PropertiesUtils.class.getClassLoader().getResourceAsStream("application.properties");
properties.load(in);
网友评论