Skip to content

Commit d0811b4

Browse files
committed
Polish "Disable Hibernate entity scanning for default JPA setup"
Closes gh-15565
1 parent 510a8e2 commit d0811b4

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,22 @@
2727
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;
2828
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;
2929
import org.springframework.util.Assert;
30+
import org.springframework.util.ClassUtils;
3031
import org.springframework.util.ObjectUtils;
3132
import org.springframework.util.StringUtils;
3233

3334
/**
3435
* Configuration properties for Hibernate.
3536
*
3637
* @author Stephane Nicoll
37-
* @author Artsiom Yudovin
3838
* @since 2.1.0
3939
* @see JpaProperties
4040
*/
4141
@ConfigurationProperties("spring.jpa.hibernate")
4242
public class HibernateProperties {
4343

44+
private static final String DISABLED_SCANNER_CLASS = "org.hibernate.boot.archive.scan.internal.DisabledScanner";
45+
4446
private final Naming naming = new Naming();
4547

4648
/**
@@ -96,7 +98,7 @@ private Map<String, Object> getAdditionalProperties(Map<String, String> existing
9698
HibernateSettings settings) {
9799
Map<String, Object> result = new HashMap<>(existing);
98100
applyNewIdGeneratorMappings(result);
99-
applyArchiveScanner(result);
101+
applyScanner(result);
100102
getNaming().applyNamingStrategies(result);
101103
String ddlAuto = determineDdlAuto(existing, settings::getDdlAuto);
102104
if (StringUtils.hasText(ddlAuto) && !"none".equals(ddlAuto)) {
@@ -123,10 +125,10 @@ else if (!result.containsKey(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS)) {
123125
}
124126
}
125127

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");
128+
private void applyScanner(Map<String, Object> result) {
129+
if (!result.containsKey(AvailableSettings.SCANNER)
130+
&& ClassUtils.isPresent(DISABLED_SCANNER_CLASS, null)) {
131+
result.put(AvailableSettings.SCANNER, DISABLED_SCANNER_CLASS);
130132
}
131133
}
132134

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,22 @@ public void useNewIdGeneratorMappingsFalse() {
125125
}
126126

127127
@Test
128-
public void useArchiveScanner() {
128+
public void scannerUsesDisabledScannerByDefault() {
129+
this.contextRunner.run(assertHibernateProperties(
130+
(hibernateProperties) -> assertThat(hibernateProperties).containsEntry(
131+
AvailableSettings.SCANNER,
132+
"org.hibernate.boot.archive.scan.internal.DisabledScanner")));
133+
}
134+
135+
@Test
136+
public void scannerCanBeCustomized() {
129137
this.contextRunner.withPropertyValues(
130138
"spring.jpa.properties.hibernate.archive.scanner:org.hibernate.boot.archive.scan.internal.StandardScanner")
131139
.run(assertHibernateProperties((hibernateProperties) -> assertThat(
132140
hibernateProperties).containsEntry(AvailableSettings.SCANNER,
133141
"org.hibernate.boot.archive.scan.internal.StandardScanner")));
134142
}
135143

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-
144144
@Test
145145
public void defaultDdlAutoIsNotInvokedIfPropertyIsSet() {
146146
this.contextRunner.withPropertyValues("spring.jpa.hibernate.ddl-auto=validate")

0 commit comments

Comments
 (0)