主配置文件编写时, 文件名能够是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 ""; } }