Skip to content

Commit ddcf596

Browse files
committed
Disable Spring Data Neo4j's open session in view by default
Closes gh-20012
1 parent 14e5445 commit ddcf596

File tree

4 files changed

+13
-36
lines changed

4 files changed

+13
-36
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,6 @@
1818

1919
import java.util.List;
2020

21-
import org.apache.commons.logging.Log;
22-
import org.apache.commons.logging.LogFactory;
2321
import org.neo4j.ogm.session.SessionFactory;
2422
import org.neo4j.ogm.session.event.EventListener;
2523

@@ -103,20 +101,11 @@ private String[] getPackagesToScan(BeanFactory beanFactory) {
103101
@ConditionalOnWebApplication(type = Type.SERVLET)
104102
@ConditionalOnClass({ WebMvcConfigurer.class, OpenSessionInViewInterceptor.class })
105103
@ConditionalOnMissingBean(OpenSessionInViewInterceptor.class)
106-
@ConditionalOnProperty(prefix = "spring.data.neo4j", name = "open-in-view", havingValue = "true",
107-
matchIfMissing = true)
104+
@ConditionalOnProperty(prefix = "spring.data.neo4j", name = "open-in-view", havingValue = "true")
108105
static class Neo4jWebConfiguration {
109106

110-
private static final Log logger = LogFactory.getLog(Neo4jWebConfiguration.class);
111-
112107
@Bean
113-
OpenSessionInViewInterceptor neo4jOpenSessionInViewInterceptor(Neo4jProperties properties) {
114-
if (properties.getOpenInView() == null) {
115-
logger.warn("spring.data.neo4j.open-in-view is enabled by default."
116-
+ "Therefore, database queries may be performed during view "
117-
+ "rendering. Explicitly configure "
118-
+ "spring.data.neo4j.open-in-view to disable this warning");
119-
}
108+
OpenSessionInViewInterceptor neo4jOpenSessionInViewInterceptor() {
120109
return new OpenSessionInViewInterceptor();
121110
}
122111

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jProperties.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -67,12 +67,6 @@ public class Neo4jProperties implements ApplicationContextAware {
6767
*/
6868
private AutoIndexMode autoIndex = AutoIndexMode.NONE;
6969

70-
/**
71-
* Register OpenSessionInViewInterceptor. Binds a Neo4j Session to the thread for the
72-
* entire processing of the request.",
73-
*/
74-
private Boolean openInView;
75-
7670
/**
7771
* Whether to use Neo4j native types wherever possible.
7872
*/
@@ -114,14 +108,6 @@ public void setAutoIndex(AutoIndexMode autoIndex) {
114108
this.autoIndex = autoIndex;
115109
}
116110

117-
public Boolean getOpenInView() {
118-
return this.openInView;
119-
}
120-
121-
public void setOpenInView(Boolean openInView) {
122-
this.openInView = openInView;
123-
}
124-
125111
public boolean isUseNativeTypes() {
126112
return this.useNativeTypes;
127113
}

spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@
408408
},
409409
{
410410
"name": "spring.data.neo4j.open-in-view",
411-
"defaultValue": true
411+
"type": "java.lang.Boolean",
412+
"description": "Register OpenSessionInViewInterceptor that binds a Neo4j Session to the thread for the entire processing of the request.",
413+
"defaultValue": false
412414
},
413415
{
414416
"name": "spring.data.neo4j.repositories.enabled",

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -76,7 +76,7 @@ void defaultConfiguration() {
7676
assertThat(context).hasSingleBean(org.neo4j.ogm.config.Configuration.class);
7777
assertThat(context).hasSingleBean(SessionFactory.class);
7878
assertThat(context).hasSingleBean(Neo4jTransactionManager.class);
79-
assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class);
79+
assertThat(context).doesNotHaveBean(OpenSessionInViewInterceptor.class);
8080
assertThat(context).doesNotHaveBean(BookmarkManager.class);
8181
});
8282
}
@@ -105,7 +105,7 @@ void customSessionFactoryShouldNotDisableOtherDefaults() {
105105
assertThat(context).hasSingleBean(SessionFactory.class);
106106
assertThat(context.getBean(SessionFactory.class)).isSameAs(context.getBean("customSessionFactory"));
107107
assertThat(context).hasSingleBean(Neo4jTransactionManager.class);
108-
assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class);
108+
assertThat(context).doesNotHaveBean(OpenSessionInViewInterceptor.class);
109109
});
110110
}
111111

@@ -136,9 +136,9 @@ void usesAutoConfigurationPackageToPickUpDomainTypes() {
136136
}
137137

138138
@Test
139-
void openSessionInViewInterceptorCanBeDisabled() {
140-
this.contextRunner.withPropertyValues("spring.data.neo4j.open-in-view:false")
141-
.run((context) -> assertThat(context).doesNotHaveBean(OpenSessionInViewInterceptor.class));
139+
void openSessionInViewInterceptorCanBeEnabled() {
140+
this.contextRunner.withPropertyValues("spring.data.neo4j.open-in-view:true")
141+
.run((context) -> assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class));
142142
}
143143

144144
@Test

0 commit comments

Comments
 (0)