主配置文件編寫時, 文件名能夠是application-{profile}.properties/ymlapp
默認使用的application.properties的配置.jvm
yml支持多文檔塊模式ide
能夠經過啓動時端口號判斷啓用的環境.this
另:經過程序獲取profile的值spa
https://blog.csdn.net/Fmuma/article/details/82787500.net
使用profile幫我解決了不一樣環境使用不一樣配置的問題,那麼若是咱們須要在代碼中獲取這個profile的值怎麼處理呢?命令行
@Component public class ProfileUtil implements ApplicationContextAware { private static ApplicationContext context = null; @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.context = applicationContext; } // 獲取當前環境參數 exp: dev,prod,test public static String getActiveProfile() { String []profiles = context.getEnvironment().getActiveProfiles(); if( ! ArrayUtils.isEmpty(profiles)){ return profiles[0]; } return ""; } }