Skip to content

Commit 88ed318

Browse files
XcrigXjkiddoCopilot
authored
process jpa properties set as env variables (hapifhir#808)
* process jpa properties set as env variables * Update src/main/java/ca/uhn/fhir/jpa/starter/util/EnvironmentHelper.java Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Jens Kristian Villadsen <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent f7e2601 commit 88ed318

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main/java/ca/uhn/fhir/jpa/starter/util/EnvironmentHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ public static Properties getHibernateProperties(
4040
properties.put(strippedKey, entry.getValue().toString());
4141
}
4242

43+
// also check for JPA properties set as environment variables, this is slightly hacky and doesn't cover all
44+
// the naming conventions Springboot allows
45+
// but there doesn't seem to be a better/deterministic way to get these properties when they are set as ENV
46+
// variables and this at least provides
47+
// a way to set them (in a docker container, for instance)
48+
Map<String, Object> jpaPropsEnv = getPropertiesStartingWith(environment, "SPRING_JPA_PROPERTIES");
49+
for (Map.Entry<String, Object> entry : jpaPropsEnv.entrySet()) {
50+
String strippedKey = entry.getKey().replace("SPRING_JPA_PROPERTIES_", "");
51+
strippedKey = strippedKey.replaceAll("_", ".");
52+
strippedKey = strippedKey.toLowerCase();
53+
properties.put(strippedKey, entry.getValue().toString());
54+
}
55+
4356
// Spring Boot Autoconfiguration defaults
4457
properties.putIfAbsent(AvailableSettings.SCANNER, "org.hibernate.boot.archive.scan.internal.DisabledScanner");
4558
properties.putIfAbsent(

0 commit comments

Comments
 (0)