resources下創建多個application.properties
application.properties
server.port=8888
imagesPath=src/main/resources/static/asserts/images/
application-dev.properties
server.port=8889
imagesPath=src/main/resources/static/asserts/images/dev/
application-test.properties
server.port=8890
imagesPath=src/main/resources/static/asserts/images/test/
test.java
public class test {
/**
* 圖片存儲路徑
*/
@Value("imagesPath")
private String imagesPath;
}
jar包運行命令
java -jar test.jar
java -jar test.jar --spring.profiles.active=test
java -jar test.jar --spring.profiles.active=dev
idea啓動在Enviromment下的Enviromment variables添加–spring.profiles.active=test