spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.49k stars 40.53k forks source link

Allow the configuration of active profiles in SpringApplication.Augmented #36660

Open odrotbohm opened 1 year ago

odrotbohm commented 1 year ago

The new support for running local application instances supported by Testcontainers based services suggests the creation of a secondary application bootstrap class in src/test/java pointing to the original one but including additional configuration. The proposed way to bootstrap such a class is through SpringApplication.from(…) returning an Augmented instance.

As that class is becoming the central bootstrap mechanism for local development, it would be nice to be able to make sure the application is always run with a dedicated profile. Especially, without having to explicitly pass it into the application either via command line arguments or a dedicated launch configuration in the IDE. Something along the lines of:

SpringApplication.from(Application::main)
  .withProfilesEnabled(…)
  .run(args);
aldex32 commented 5 months ago

Hello, it would be very useful feature in my view.

tschuehly commented 2 months ago

This would indeed be very helpful!

jurri-cz commented 4 weeks ago

Stumbling upon this, I found a possible workaround to OP by adding a program argument --spring.profiles.active=some-profile to the call of Augmented. Something like this:

    public static void main(String... args) {
        String[] augmentedArgs = Stream.concat(
                Stream.of("--spring.profiles.active=local-run"),
                Stream.of(args)
        ).toArray(String[]::new);

        SpringApplication
                .from(Application::main)
                .run(augmentedArgs);
    }