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 230247a19e..a6ceb07d68 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 @@ -18,6 +18,8 @@ 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; @@ -117,8 +119,23 @@ public class Neo4jDataAutoConfiguration { @Configuration protected static class Neo4jWebMvcConfiguration implements WebMvcConfigurer { + private static final Log logger = LogFactory + .getLog(Neo4jWebMvcConfiguration.class); + + private final Neo4jProperties neo4jProperties; + + protected Neo4jWebMvcConfiguration(Neo4jProperties neo4jProperties) { + this.neo4jProperties = neo4jProperties; + } + @Bean public OpenSessionInViewInterceptor neo4jOpenSessionInViewInterceptor() { + if (this.neo4jProperties.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"); + } 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 103597ab73..ef4524eaff 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 @@ -66,6 +66,12 @@ 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; + private final Embedded embedded = new Embedded(); private ClassLoader classLoader = Neo4jProperties.class.getClassLoader(); @@ -102,6 +108,14 @@ public class Neo4jProperties implements ApplicationContextAware { this.autoIndex = autoIndex; } + public Boolean getOpenInView() { + return this.openInView; + } + + public void setOpenInView(Boolean openInView) { + this.openInView = openInView; + } + public Embedded getEmbedded() { return this.embedded; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java index 74d8c6e521..81be8a39f7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java @@ -22,6 +22,9 @@ import java.util.Map; import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; @@ -214,8 +217,23 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware { @Configuration protected static class JpaWebMvcConfiguration implements WebMvcConfigurer { + private static final Log logger = LogFactory + .getLog(JpaWebMvcConfiguration.class); + + private final JpaProperties jpaProperties; + + protected JpaWebMvcConfiguration(JpaProperties jpaProperties) { + this.jpaProperties = jpaProperties; + } + @Bean public OpenEntityManagerInViewInterceptor openEntityManagerInViewInterceptor() { + if (this.jpaProperties.getOpenInView() == null) { + logger.warn("spring.jpa.open-in-view is enabled by default. " + + "Therefore, database queries may be performed during view " + + "rendering. Explicitly configure " + + "spring.jpa.open-in-view to disable this warning"); + } return new OpenEntityManagerInViewInterceptor(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java index 896f88edaf..194e3a0413 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java @@ -72,6 +72,12 @@ public class JpaProperties { */ private boolean showSql = false; + /** + * Register OpenEntityManagerInViewInterceptor. Binds a JPA EntityManager to the + * thread for the entire processing of the request. + */ + private Boolean openInView; + private Hibernate hibernate = new Hibernate(); public Map getProperties() { @@ -118,6 +124,14 @@ public class JpaProperties { this.showSql = showSql; } + public Boolean getOpenInView() { + return this.openInView; + } + + public void setOpenInView(Boolean openInView) { + this.openInView = openInView; + } + public Hibernate getHibernate() { return this.hibernate; } 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 7043cae564..26964e8112 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 @@ -145,12 +145,6 @@ "description": "Enable Mongo repositories.", "defaultValue": true }, - { - "name": "spring.data.neo4j.open-in-view", - "type": "java.lang.Boolean", - "description": "Register OpenSessionInViewInterceptor. Binds a Neo4j Session to the thread for the entire processing of the request.", - "defaultValue": false - }, { "name": "spring.data.neo4j.repositories.enabled", "type": "java.lang.Boolean", @@ -227,12 +221,6 @@ "description": "MBeanServer bean name.", "defaultValue": "mbeanServer" }, - { - "name": "spring.jpa.open-in-view", - "type": "java.lang.Boolean", - "description": "Register OpenEntityManagerInViewInterceptor. Binds a JPA EntityManager to the thread for the entire processing of the request.", - "defaultValue": true - }, { "name": "spring.jta.enabled", "type": "java.lang.Boolean", diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 2ccc565a58..c94f64c1a6 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -3723,7 +3723,7 @@ By default, if you are running a web application, the session is bound to the th the entire processing of the request (i.e. the "Open Session in View" pattern). If you don't want this behavior add the following to your `application.properties`: - +[source,properties,indent=0] ---- spring.data.neo4j.open-in-view=false ---- diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/resources/application.properties index 330237435d..15b2174d3b 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/resources/application.properties @@ -1,3 +1,3 @@ spring.h2.console.enabled=true - +spring.jpa.open-in-view=true logging.level.org.hibernate.SQL=debug diff --git a/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/resources/application.properties index e69de29bb2..6dabd65d3e 100644 --- a/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-data-neo4j/src/main/resources/application.properties @@ -0,0 +1 @@ +# spring.data.neo4j.open-in-view=true diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties index a84efce66e..06f17c388e 100644 --- a/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties @@ -1,5 +1,4 @@ endpoints.flyway.web.enabled=true - spring.jpa.hibernate.ddl-auto=validate - -spring.h2.console.enabled=true \ No newline at end of file +spring.jpa.open-in-view=true +spring.h2.console.enabled=true diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-jpa/src/main/resources/application.properties new file mode 100644 index 0000000000..1716f9c843 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-jpa/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.jpa.open-in-view=true diff --git a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/resources/application.properties index 8889971d3d..c2a3691616 100644 --- a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/resources/application.properties @@ -1,2 +1,3 @@ logging.level.com.atomikos=WARN -spring.artemis.embedded.queues=accounts \ No newline at end of file +spring.artemis.embedded.queues=accounts +spring.jpa.open-in-view=true diff --git a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/resources/application.properties index 66db4c7ada..ba2e3e18ba 100644 --- a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/resources/application.properties @@ -1 +1,2 @@ -spring.artemis.embedded.queues=accounts \ No newline at end of file +spring.artemis.embedded.queues=accounts +spring.jpa.open-in-view=true diff --git a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/resources/application.properties index 0b5521eeab..89c0de031d 100644 --- a/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-jta-jndi/src/main/resources/application.properties @@ -1,2 +1,3 @@ -spring.jpa.generate-ddl=true spring.datasource.jndi-name=java:jboss/datasources/bootdemo +spring.jpa.generate-ddl=true +spring.jpa.open-in-view=true diff --git a/spring-boot-samples/spring-boot-sample-jta-narayana/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-jta-narayana/src/main/resources/application.properties index c7c3a91e59..b4f779ce63 100644 --- a/spring-boot-samples/spring-boot-sample-jta-narayana/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-jta-narayana/src/main/resources/application.properties @@ -1,2 +1,3 @@ +logging.level.com.arjuna=INFO spring.artemis.embedded.queues=accounts -logging.level.com.arjuna=INFO \ No newline at end of file +spring.jpa.open-in-view=true diff --git a/spring-boot-samples/spring-boot-sample-test/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-test/src/main/resources/application.properties index c28dbb20bc..db93553871 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/main/resources/application.properties +++ b/spring-boot-samples/spring-boot-sample-test/src/main/resources/application.properties @@ -1 +1,2 @@ spring.datasource.url=jdbc:mysql://localhost/doesnotexist +spring.jpa.open-in-view=true