Skip to content

方式一:spring.profiles.active

  • resources/application.properties中

    properties
    spring.profiles.active=dev
  • resources/application.yml中

    yml
    spring:
      profiles:
        active: dev

方式二:命令行激活

shell
java -jar app.jar --spring.profiles.active=dev

方式三:idea和eclipse的配置

在这里插入图片描述

在这里插入图片描述

方式四:启动程序中设置(不推荐)

public static void main(String[] args) {
    SpringApplication app = new SpringApplication(YourApplication.class);
    app.setAdditionalProfiles("prod");
    app.run(args);
}

MIT版权,未经许可禁止任何形式的转载