springboot 多環境-@value

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

idea

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章