Setting the default active profile in Spring-boot

前端 未结 14 1932
感动是毒
感动是毒 2020-12-13 08:20

I want my default active profile to be production if -Dspring.profiles.active is not set.

I tried the following in my application.pro

14条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 09:05

    Put this in the App.java:

    public static void main(String[] args) throws UnknownHostException {
        SpringApplication app = new SpringApplication(App.class);
        SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
        if (!source.containsProperty("spring.profiles.active") &&
                !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {
    
            app.setAdditionalProfiles("production");
        }
        ...
    }
    

    This is how it is done in JHipster

提交回复
热议问题