Skip to content

Commit 510a8e2

Browse files
ayudovinsnicoll
authored andcommitted
Disable Hibernate entity scanning for default JPA setup
See gh-15565
1 parent 3354756 commit 510a8e2

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateProperties.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* Configuration properties for Hibernate.
3535
*
3636
* @author Stephane Nicoll
37+
* @author Artsiom Yudovin
3738
* @since 2.1.0
3839
* @see JpaProperties
3940
*/
@@ -95,6 +96,7 @@ private Map<String, Object> getAdditionalProperties(Map<String, String> existing
9596
HibernateSettings settings) {
9697
Map<String, Object> result = new HashMap<>(existing);
9798
applyNewIdGeneratorMappings(result);
99+
applyArchiveScanner(result);
98100
getNaming().applyNamingStrategies(result);
99101
String ddlAuto = determineDdlAuto(existing, settings::getDdlAuto);
100102
if (StringUtils.hasText(ddlAuto) && !"none".equals(ddlAuto)) {
@@ -121,6 +123,13 @@ else if (!result.containsKey(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS)) {
121123
}
122124
}
123125

126+
private void applyArchiveScanner(Map<String, Object> result) {
127+
if (!result.containsKey(AvailableSettings.SCANNER)) {
128+
result.put(AvailableSettings.SCANNER,
129+
"org.hibernate.boot.archive.scan.internal.DisabledScanner");
130+
}
131+
}
132+
124133
private String determineDdlAuto(Map<String, String> existing,
125134
Supplier<String> defaultDdlAuto) {
126135
String ddlAuto = existing.get(AvailableSettings.HBM2DDL_AUTO);

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernatePropertiesTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* Tests for {@link HibernateProperties}.
4444
*
4545
* @author Stephane Nicoll
46+
* @author Artsiom Yudovin
4647
*/
4748
public class HibernatePropertiesTests {
4849

@@ -123,6 +124,23 @@ public void useNewIdGeneratorMappingsFalse() {
123124
"false")));
124125
}
125126

127+
@Test
128+
public void useArchiveScanner() {
129+
this.contextRunner.withPropertyValues(
130+
"spring.jpa.properties.hibernate.archive.scanner:org.hibernate.boot.archive.scan.internal.StandardScanner")
131+
.run(assertHibernateProperties((hibernateProperties) -> assertThat(
132+
hibernateProperties).containsEntry(AvailableSettings.SCANNER,
133+
"org.hibernate.boot.archive.scan.internal.StandardScanner")));
134+
}
135+
136+
@Test
137+
public void defaultArchiveScanner() {
138+
this.contextRunner.run(assertHibernateProperties(
139+
(hibernateProperties) -> assertThat(hibernateProperties).containsEntry(
140+
AvailableSettings.SCANNER,
141+
"org.hibernate.boot.archive.scan.internal.DisabledScanner")));
142+
}
143+
126144
@Test
127145
public void defaultDdlAutoIsNotInvokedIfPropertyIsSet() {
128146
this.contextRunner.withPropertyValues("spring.jpa.hibernate.ddl-auto=validate")

0 commit comments

Comments
 (0)