springboot配置文件自定義字段在dev/prod下的自動讀取


讀取自定義字段

1.定義字段

application.properties

path.pictrue.brand=/home/abc/Pictures/brand/

application-prod.properties

path.pictrue.brand=/home/xyz/Pictures/brand/

2.讀取字段

PropertiesConfig.java

@Component
public class PropertiesConfig {

    @Value("${path.pictrue.brand}")
    public String pathBrand;
}

3.在需要使用的類中:

@Autowired
private PropertiesConfig pConfig;


public void testPicture() {
        
    System.out.println(pConfig.pathBrand);
}

4.生產jar包后:

java -jar xxxxx.jar 使用的是application.properties

java -jar -Dspring.profiles.active=prod xxxxx.jar 則使用的是application-prod.properties

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM