diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemContent.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemContent.java index 948da58824..aca731e937 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemContent.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemContent.java @@ -120,8 +120,8 @@ public final class PemContent { if (isPresentInText(content)) { return new PemContent(content); } - try { - return load(resourceLoader.getResource(content).getInputStream()); + try (InputStream in = resourceLoader.getResource(content).getInputStream()) { + return load(in); } catch (IOException | UncheckedIOException ex) { throw new IOException("Error reading certificate or key from file '%s'".formatted(content), ex);