mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-05-02 19:30:23 +01:00
Log warning when open-in-view is implicitly enabled for JPA or Neo4j
Closes gh-7107
This commit is contained in:
+17
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
+14
@@ -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;
|
||||
}
|
||||
|
||||
+18
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
+14
@@ -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<String, String> 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;
|
||||
}
|
||||
|
||||
-12
@@ -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",
|
||||
|
||||
@@ -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
|
||||
----
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
spring.h2.console.enabled=true
|
||||
|
||||
spring.jpa.open-in-view=true
|
||||
logging.level.org.hibernate.SQL=debug
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
# spring.data.neo4j.open-in-view=true
|
||||
|
||||
+2
-3
@@ -1,5 +1,4 @@
|
||||
endpoints.flyway.web.enabled=true
|
||||
|
||||
spring.jpa.hibernate.ddl-auto=validate
|
||||
|
||||
spring.h2.console.enabled=true
|
||||
spring.jpa.open-in-view=true
|
||||
spring.h2.console.enabled=true
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
spring.jpa.open-in-view=true
|
||||
+2
-1
@@ -1,2 +1,3 @@
|
||||
logging.level.com.atomikos=WARN
|
||||
spring.artemis.embedded.queues=accounts
|
||||
spring.artemis.embedded.queues=accounts
|
||||
spring.jpa.open-in-view=true
|
||||
|
||||
+2
-1
@@ -1 +1,2 @@
|
||||
spring.artemis.embedded.queues=accounts
|
||||
spring.artemis.embedded.queues=accounts
|
||||
spring.jpa.open-in-view=true
|
||||
|
||||
+2
-1
@@ -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
|
||||
|
||||
+2
-1
@@ -1,2 +1,3 @@
|
||||
logging.level.com.arjuna=INFO
|
||||
spring.artemis.embedded.queues=accounts
|
||||
logging.level.com.arjuna=INFO
|
||||
spring.jpa.open-in-view=true
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
spring.datasource.url=jdbc:mysql://localhost/doesnotexist
|
||||
spring.jpa.open-in-view=true
|
||||
|
||||
Reference in New Issue
Block a user