Commit ddcf5966 authored by Stephane Nicoll's avatar Stephane Nicoll

Disable Spring Data Neo4j's open session in view by default

Closes gh-20012
parent 14e54451
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; ...@@ -18,8 +18,6 @@ package org.springframework.boot.autoconfigure.data.neo4j;
import java.util.List; 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.SessionFactory;
import org.neo4j.ogm.session.event.EventListener; import org.neo4j.ogm.session.event.EventListener;
...@@ -103,20 +101,11 @@ public class Neo4jDataAutoConfiguration { ...@@ -103,20 +101,11 @@ public class Neo4jDataAutoConfiguration {
@ConditionalOnWebApplication(type = Type.SERVLET) @ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnClass({ WebMvcConfigurer.class, OpenSessionInViewInterceptor.class }) @ConditionalOnClass({ WebMvcConfigurer.class, OpenSessionInViewInterceptor.class })
@ConditionalOnMissingBean(OpenSessionInViewInterceptor.class) @ConditionalOnMissingBean(OpenSessionInViewInterceptor.class)
@ConditionalOnProperty(prefix = "spring.data.neo4j", name = "open-in-view", havingValue = "true", @ConditionalOnProperty(prefix = "spring.data.neo4j", name = "open-in-view", havingValue = "true")
matchIfMissing = true)
static class Neo4jWebConfiguration { static class Neo4jWebConfiguration {
private static final Log logger = LogFactory.getLog(Neo4jWebConfiguration.class);
@Bean @Bean
OpenSessionInViewInterceptor neo4jOpenSessionInViewInterceptor(Neo4jProperties properties) { OpenSessionInViewInterceptor neo4jOpenSessionInViewInterceptor() {
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");
}
return new OpenSessionInViewInterceptor(); return new OpenSessionInViewInterceptor();
} }
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -67,12 +67,6 @@ public class Neo4jProperties implements ApplicationContextAware { ...@@ -67,12 +67,6 @@ public class Neo4jProperties implements ApplicationContextAware {
*/ */
private AutoIndexMode autoIndex = AutoIndexMode.NONE; 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. * Whether to use Neo4j native types wherever possible.
*/ */
...@@ -114,14 +108,6 @@ public class Neo4jProperties implements ApplicationContextAware { ...@@ -114,14 +108,6 @@ public class Neo4jProperties implements ApplicationContextAware {
this.autoIndex = autoIndex; this.autoIndex = autoIndex;
} }
public Boolean getOpenInView() {
return this.openInView;
}
public void setOpenInView(Boolean openInView) {
this.openInView = openInView;
}
public boolean isUseNativeTypes() { public boolean isUseNativeTypes() {
return this.useNativeTypes; return this.useNativeTypes;
} }
......
...@@ -408,7 +408,9 @@ ...@@ -408,7 +408,9 @@
}, },
{ {
"name": "spring.data.neo4j.open-in-view", "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", "name": "spring.data.neo4j.repositories.enabled",
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -76,7 +76,7 @@ class Neo4jDataAutoConfigurationTests { ...@@ -76,7 +76,7 @@ class Neo4jDataAutoConfigurationTests {
assertThat(context).hasSingleBean(org.neo4j.ogm.config.Configuration.class); assertThat(context).hasSingleBean(org.neo4j.ogm.config.Configuration.class);
assertThat(context).hasSingleBean(SessionFactory.class); assertThat(context).hasSingleBean(SessionFactory.class);
assertThat(context).hasSingleBean(Neo4jTransactionManager.class); assertThat(context).hasSingleBean(Neo4jTransactionManager.class);
assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class); assertThat(context).doesNotHaveBean(OpenSessionInViewInterceptor.class);
assertThat(context).doesNotHaveBean(BookmarkManager.class); assertThat(context).doesNotHaveBean(BookmarkManager.class);
}); });
} }
...@@ -105,7 +105,7 @@ class Neo4jDataAutoConfigurationTests { ...@@ -105,7 +105,7 @@ class Neo4jDataAutoConfigurationTests {
assertThat(context).hasSingleBean(SessionFactory.class); assertThat(context).hasSingleBean(SessionFactory.class);
assertThat(context.getBean(SessionFactory.class)).isSameAs(context.getBean("customSessionFactory")); assertThat(context.getBean(SessionFactory.class)).isSameAs(context.getBean("customSessionFactory"));
assertThat(context).hasSingleBean(Neo4jTransactionManager.class); assertThat(context).hasSingleBean(Neo4jTransactionManager.class);
assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class); assertThat(context).doesNotHaveBean(OpenSessionInViewInterceptor.class);
}); });
} }
...@@ -136,9 +136,9 @@ class Neo4jDataAutoConfigurationTests { ...@@ -136,9 +136,9 @@ class Neo4jDataAutoConfigurationTests {
} }
@Test @Test
void openSessionInViewInterceptorCanBeDisabled() { void openSessionInViewInterceptorCanBeEnabled() {
this.contextRunner.withPropertyValues("spring.data.neo4j.open-in-view:false") this.contextRunner.withPropertyValues("spring.data.neo4j.open-in-view:true")
.run((context) -> assertThat(context).doesNotHaveBean(OpenSessionInViewInterceptor.class)); .run((context) -> assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class));
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment