/** * Template method delegating to * {@link #configurePropertySources(ConfigurableEnvironment, String[])} and * {@link #configureProfiles(ConfigurableEnvironment, String[])} in that order. * Override this method for complete control over Environment customization, or one of * the above for fine-grained control over property sources or profiles, respectively. * @param environment this application's environment * @param args arguments passed to the {@code run} method * @see #configureProfiles(ConfigurableEnvironment, String[]) * @see #configurePropertySources(ConfigurableEnvironment, String[]) */ protected void configureEnvironment(ConfigurableEnvironment environment, String[] args) { if (this.addConversionService) { ConversionService conversionService = ApplicationConversionService .getSharedInstance(); environment.setConversionService( (ConfigurableConversionService) conversionService); } configurePropertySources(environment, args); configureProfiles(environment, args); }
@Override protected void configureProfiles(final ConfigurableEnvironment environment, final String[] args) { super.configureProfiles(environment, args); final boolean standaloneActive = environment.acceptsProfiles(StarterProfiles.STANDALONE); final boolean stagingActive = environment.acceptsProfiles(StarterProfiles.STAGING); final boolean productionActive = environment.acceptsProfiles(StarterProfiles.PRODUCTION); if (stagingActive && productionActive) { throw new IllegalStateException("Cannot activate staging and production profiles at the same time."); } else if (productionActive || stagingActive) { System.out.println("Activating " + (productionActive ? StarterProfiles.PRODUCTION : StarterProfiles.STAGING) + " profile."); } else if (standaloneActive) { System.out.println("Activating " + "the default standalone profile."); } else { throw new IllegalStateException( "Unknown profiles specified. Please specify one of default, staging or production."); } }