diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java index fa589ce591f..443652f7b1f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -534,6 +534,18 @@ public class SpringApplicationBuilder { return this; } + /** + * Prefix that should be applied when obtaining configuration properties from the + * system environment. + * @param environmentPrefix the environment property prefix to set + * @return the current builder + * @since 2.5.0 + */ + public SpringApplicationBuilder environmentPrefix(String environmentPrefix) { + this.application.setEnvironmentPrefix(environmentPrefix); + return this; + } + /** * {@link ResourceLoader} for the application context. If a custom class loader is * needed, this is where it would be added. diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java index de6139cb6b5..634d2a337a2 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -291,6 +291,12 @@ class SpringApplicationBuilderTests { assertThat(this.context.getBean("test")).isEqualTo("spring"); } + @Test + void setEnvironmentPrefix() { + SpringApplicationBuilder builder = new SpringApplicationBuilder(ExampleConfig.class).environmentPrefix("test"); + assertThat(builder.application().getEnvironmentPrefix()).isEqualTo("test"); + } + @Configuration(proxyBeanMethods = false) static class ExampleConfig {