diff --git a/core/spring-boot/src/main/java/org/springframework/boot/env/RandomValuePropertySource.java b/core/spring-boot/src/main/java/org/springframework/boot/env/RandomValuePropertySource.java index 2ac32fd1165..6e5c9a12323 100644 --- a/core/spring-boot/src/main/java/org/springframework/boot/env/RandomValuePropertySource.java +++ b/core/spring-boot/src/main/java/org/springframework/boot/env/RandomValuePropertySource.java @@ -16,6 +16,7 @@ package org.springframework.boot.env; +import java.security.SecureRandom; import java.util.HexFormat; import java.util.OptionalInt; import java.util.OptionalLong; @@ -79,7 +80,7 @@ public class RandomValuePropertySource extends PropertySource { } public RandomValuePropertySource(String name) { - super(name, new Random()); + super(name, new SecureRandom()); } @Override diff --git a/core/spring-boot/src/test/java/org/springframework/boot/env/RandomValuePropertySourceTests.java b/core/spring-boot/src/test/java/org/springframework/boot/env/RandomValuePropertySourceTests.java index 5ed84539b2b..8cac2a0b48a 100644 --- a/core/spring-boot/src/test/java/org/springframework/boot/env/RandomValuePropertySourceTests.java +++ b/core/spring-boot/src/test/java/org/springframework/boot/env/RandomValuePropertySourceTests.java @@ -50,7 +50,7 @@ class RandomValuePropertySourceTests { @Test void getPropertyWhenStringReturnsValue() { - assertThat(this.source.getProperty("random.string")).isNotNull(); + assertThat(this.source.getProperty("random.string")).isNotNull().asString().containsPattern("^[0-9a-f]{32}$"); } @Test