Disable Hibernate entity scanning for default JPA setup
See gh-15565
This commit is contained in:
parent
33547569db
commit
510a8e2ec1
|
@ -34,6 +34,7 @@ import org.springframework.util.StringUtils;
|
|||
* Configuration properties for Hibernate.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Artsiom Yudovin
|
||||
* @since 2.1.0
|
||||
* @see JpaProperties
|
||||
*/
|
||||
|
@ -95,6 +96,7 @@ public class HibernateProperties {
|
|||
HibernateSettings settings) {
|
||||
Map<String, Object> result = new HashMap<>(existing);
|
||||
applyNewIdGeneratorMappings(result);
|
||||
applyArchiveScanner(result);
|
||||
getNaming().applyNamingStrategies(result);
|
||||
String ddlAuto = determineDdlAuto(existing, settings::getDdlAuto);
|
||||
if (StringUtils.hasText(ddlAuto) && !"none".equals(ddlAuto)) {
|
||||
|
@ -121,6 +123,13 @@ public class HibernateProperties {
|
|||
}
|
||||
}
|
||||
|
||||
private void applyArchiveScanner(Map<String, Object> result) {
|
||||
if (!result.containsKey(AvailableSettings.SCANNER)) {
|
||||
result.put(AvailableSettings.SCANNER,
|
||||
"org.hibernate.boot.archive.scan.internal.DisabledScanner");
|
||||
}
|
||||
}
|
||||
|
||||
private String determineDdlAuto(Map<String, String> existing,
|
||||
Supplier<String> defaultDdlAuto) {
|
||||
String ddlAuto = existing.get(AvailableSettings.HBM2DDL_AUTO);
|
||||
|
|
|
@ -43,6 +43,7 @@ import static org.mockito.Mockito.verify;
|
|||
* Tests for {@link HibernateProperties}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
public class HibernatePropertiesTests {
|
||||
|
||||
|
@ -123,6 +124,23 @@ public class HibernatePropertiesTests {
|
|||
"false")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useArchiveScanner() {
|
||||
this.contextRunner.withPropertyValues(
|
||||
"spring.jpa.properties.hibernate.archive.scanner:org.hibernate.boot.archive.scan.internal.StandardScanner")
|
||||
.run(assertHibernateProperties((hibernateProperties) -> assertThat(
|
||||
hibernateProperties).containsEntry(AvailableSettings.SCANNER,
|
||||
"org.hibernate.boot.archive.scan.internal.StandardScanner")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultArchiveScanner() {
|
||||
this.contextRunner.run(assertHibernateProperties(
|
||||
(hibernateProperties) -> assertThat(hibernateProperties).containsEntry(
|
||||
AvailableSettings.SCANNER,
|
||||
"org.hibernate.boot.archive.scan.internal.DisabledScanner")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultDdlAutoIsNotInvokedIfPropertyIsSet() {
|
||||
this.contextRunner.withPropertyValues("spring.jpa.hibernate.ddl-auto=validate")
|
||||
|
|
Loading…
Reference in New Issue