Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
5aa66305
Commit
5aa66305
authored
Oct 30, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Log warning when open-in-view is implicitly enabled for JPA or Neo4j
Closes gh-7107
parent
95d8fe70
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
78 additions
and
21 deletions
+78
-21
Neo4jDataAutoConfiguration.java
.../autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java
+17
-0
Neo4jProperties.java
...mework/boot/autoconfigure/data/neo4j/Neo4jProperties.java
+14
-0
JpaBaseConfiguration.java
...work/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java
+18
-0
JpaProperties.java
...ngframework/boot/autoconfigure/orm/jpa/JpaProperties.java
+14
-0
additional-spring-configuration-metadata.json
...es/META-INF/additional-spring-configuration-metadata.json
+0
-12
spring-boot-features.adoc
...ing-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+1
-1
application.properties
...sample-data-jpa/src/main/resources/application.properties
+1
-1
application.properties
...mple-data-neo4j/src/main/resources/application.properties
+1
-0
application.properties
...t-sample-flyway/src/main/resources/application.properties
+2
-3
application.properties
...boot-sample-jpa/src/main/resources/application.properties
+1
-0
application.properties
...le-jta-atomikos/src/main/resources/application.properties
+2
-1
application.properties
...le-jta-bitronix/src/main/resources/application.properties
+2
-1
application.properties
...sample-jta-jndi/src/main/resources/application.properties
+2
-1
application.properties
...le-jta-narayana/src/main/resources/application.properties
+2
-1
application.properties
...oot-sample-test/src/main/resources/application.properties
+1
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java
View file @
5aa66305
...
...
@@ -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
();
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jProperties.java
View file @
5aa66305
...
...
@@ -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
;
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java
View file @
5aa66305
...
...
@@ -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
();
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java
View file @
5aa66305
...
...
@@ -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
;
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
View file @
5aa66305
...
...
@@ -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"
,
...
...
spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
5aa66305
...
...
@@ -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
----
...
...
spring-boot-samples/spring-boot-sample-data-jpa/src/main/resources/application.properties
View file @
5aa66305
spring.h2.console.enabled
=
true
spring.jpa.open-in-view
=
true
logging.level.org.hibernate.SQL
=
debug
spring-boot-samples/spring-boot-sample-data-neo4j/src/main/resources/application.properties
View file @
5aa66305
# spring.data.neo4j.open-in-view=true
spring-boot-samples/spring-boot-sample-flyway/src/main/resources/application.properties
View file @
5aa66305
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
spring-boot-samples/spring-boot-sample-jpa/src/main/resources/application.properties
0 → 100644
View file @
5aa66305
spring.jpa.open-in-view
=
true
spring-boot-samples/spring-boot-sample-jta-atomikos/src/main/resources/application.properties
View file @
5aa66305
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
spring-boot-samples/spring-boot-sample-jta-bitronix/src/main/resources/application.properties
View file @
5aa66305
spring.artemis.embedded.queues
=
accounts
\ No newline at end of file
spring.artemis.embedded.queues
=
accounts
spring.jpa.open-in-view
=
true
spring-boot-samples/spring-boot-sample-jta-jndi/src/main/resources/application.properties
View file @
5aa66305
spring.jpa.generate-ddl
=
true
spring.datasource.jndi-name
=
java:jboss/datasources/bootdemo
spring.jpa.generate-ddl
=
true
spring.jpa.open-in-view
=
true
spring-boot-samples/spring-boot-sample-jta-narayana/src/main/resources/application.properties
View file @
5aa66305
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
spring-boot-samples/spring-boot-sample-test/src/main/resources/application.properties
View file @
5aa66305
spring.datasource.url
=
jdbc:mysql://localhost/doesnotexist
spring.jpa.open-in-view
=
true
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment