diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java index 585efa5682..bc02c39ce4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,6 @@ package org.springframework.boot.autoconfigure.data.neo4j; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.neo4j.ogm.session.SessionFactory; import org.neo4j.ogm.session.event.EventListener; @@ -103,20 +101,11 @@ public class Neo4jDataAutoConfiguration { @ConditionalOnWebApplication(type = Type.SERVLET) @ConditionalOnClass({ WebMvcConfigurer.class, OpenSessionInViewInterceptor.class }) @ConditionalOnMissingBean(OpenSessionInViewInterceptor.class) - @ConditionalOnProperty(prefix = "spring.data.neo4j", name = "open-in-view", havingValue = "true", - matchIfMissing = true) + @ConditionalOnProperty(prefix = "spring.data.neo4j", name = "open-in-view", havingValue = "true") static class Neo4jWebConfiguration { - private static final Log logger = LogFactory.getLog(Neo4jWebConfiguration.class); - @Bean - OpenSessionInViewInterceptor neo4jOpenSessionInViewInterceptor(Neo4jProperties properties) { - if (properties.getOpenInView() == null) { - logger.warn("spring.data.neo4j.open-in-view is enabled by default." - + "Therefore, database queries may be performed during view " - + "rendering. Explicitly configure " - + "spring.data.neo4j.open-in-view to disable this warning"); - } + OpenSessionInViewInterceptor neo4jOpenSessionInViewInterceptor() { return new OpenSessionInViewInterceptor(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jProperties.java index 7eff8e1289..2daa039183 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,12 +67,6 @@ public class Neo4jProperties implements ApplicationContextAware { */ private AutoIndexMode autoIndex = AutoIndexMode.NONE; - /** - * Register OpenSessionInViewInterceptor. Binds a Neo4j Session to the thread for the - * entire processing of the request.", - */ - private Boolean openInView; - /** * Whether to use Neo4j native types wherever possible. */ @@ -114,14 +108,6 @@ public class Neo4jProperties implements ApplicationContextAware { this.autoIndex = autoIndex; } - public Boolean getOpenInView() { - return this.openInView; - } - - public void setOpenInView(Boolean openInView) { - this.openInView = openInView; - } - public boolean isUseNativeTypes() { return this.useNativeTypes; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 932bbbc1b9..d24edfe6b7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -408,7 +408,9 @@ }, { "name": "spring.data.neo4j.open-in-view", - "defaultValue": true + "type": "java.lang.Boolean", + "description": "Register OpenSessionInViewInterceptor that binds a Neo4j Session to the thread for the entire processing of the request.", + "defaultValue": false }, { "name": "spring.data.neo4j.repositories.enabled", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java index 8c63012c34..1f523d026e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,7 +76,7 @@ class Neo4jDataAutoConfigurationTests { assertThat(context).hasSingleBean(org.neo4j.ogm.config.Configuration.class); assertThat(context).hasSingleBean(SessionFactory.class); assertThat(context).hasSingleBean(Neo4jTransactionManager.class); - assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class); + assertThat(context).doesNotHaveBean(OpenSessionInViewInterceptor.class); assertThat(context).doesNotHaveBean(BookmarkManager.class); }); } @@ -105,7 +105,7 @@ class Neo4jDataAutoConfigurationTests { assertThat(context).hasSingleBean(SessionFactory.class); assertThat(context.getBean(SessionFactory.class)).isSameAs(context.getBean("customSessionFactory")); assertThat(context).hasSingleBean(Neo4jTransactionManager.class); - assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class); + assertThat(context).doesNotHaveBean(OpenSessionInViewInterceptor.class); }); } @@ -136,9 +136,9 @@ class Neo4jDataAutoConfigurationTests { } @Test - void openSessionInViewInterceptorCanBeDisabled() { - this.contextRunner.withPropertyValues("spring.data.neo4j.open-in-view:false") - .run((context) -> assertThat(context).doesNotHaveBean(OpenSessionInViewInterceptor.class)); + void openSessionInViewInterceptorCanBeEnabled() { + this.contextRunner.withPropertyValues("spring.data.neo4j.open-in-view:true") + .run((context) -> assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class)); } @Test