Last active
August 13, 2023 02:40
-
-
Save sandipchitale/98562c3d9c3e88f459904143297196c7 to your computer and use it in GitHub Desktop.
Dynamicall add a property source to inject additional property based on another property #springboot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Order(Ordered.LOWEST_PRECEDENCE) | |
public static class OAuth2ClientPropertiesSchemeAdjusterEnvironmentPostProcessor implements EnvironmentPostProcessor { | |
@Override | |
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { | |
String asScheme = "http"; | |
if ("true".equals(environment.getProperty("server.ssl.enabled"))) { | |
asScheme = "https"; | |
} | |
// Set the property authorizationserver.scheme which will later be replaced when | |
// it appears as ${authorizationserver.scheme} any other properties value | |
environment.getPropertySources().addFirst(new MapPropertySource("authorizationserver.scheme", | |
Map.of("authorizationserver.scheme", asScheme))); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
org.springframework.boot.env.EnvironmentPostProcessor=OAuth2ClientPropertiesSchemeAdjusterEnvironmentPostProcessor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment