Skip to content

Instantly share code, notes, and snippets.

@sandipchitale
Last active August 13, 2023 02:40
Show Gist options
  • Save sandipchitale/98562c3d9c3e88f459904143297196c7 to your computer and use it in GitHub Desktop.
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
@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)));
}
}
org.springframework.boot.env.EnvironmentPostProcessor=OAuth2ClientPropertiesSchemeAdjusterEnvironmentPostProcessor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment