Disable Spring Data Neo4j's open session in view by default
Closes gh-20012
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,8 +18,6 @@ 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;
|
||||
|
||||
@@ -103,20 +101,11 @@ public class Neo4jDataAutoConfiguration {
|
||||
@ConditionalOnWebApplication(type = Type.SERVLET)
|
||||
@ConditionalOnClass({ WebMvcConfigurer.class, OpenSessionInViewInterceptor.class })
|
||||
@ConditionalOnMissingBean(OpenSessionInViewInterceptor.class)
|
||||
@ConditionalOnProperty(prefix = "spring.data.neo4j", name = "open-in-view", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.data.neo4j", name = "open-in-view", havingValue = "true")
|
||||
static class Neo4jWebConfiguration {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(Neo4jWebConfiguration.class);
|
||||
|
||||
@Bean
|
||||
OpenSessionInViewInterceptor neo4jOpenSessionInViewInterceptor(Neo4jProperties properties) {
|
||||
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");
|
||||
}
|
||||
OpenSessionInViewInterceptor neo4jOpenSessionInViewInterceptor() {
|
||||
return new OpenSessionInViewInterceptor();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -67,12 +67,6 @@ 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;
|
||||
|
||||
/**
|
||||
* Whether to use Neo4j native types wherever possible.
|
||||
*/
|
||||
@@ -114,14 +108,6 @@ public class Neo4jProperties implements ApplicationContextAware {
|
||||
this.autoIndex = autoIndex;
|
||||
}
|
||||
|
||||
public Boolean getOpenInView() {
|
||||
return this.openInView;
|
||||
}
|
||||
|
||||
public void setOpenInView(Boolean openInView) {
|
||||
this.openInView = openInView;
|
||||
}
|
||||
|
||||
public boolean isUseNativeTypes() {
|
||||
return this.useNativeTypes;
|
||||
}
|
||||
|
||||
@@ -408,7 +408,9 @@
|
||||
},
|
||||
{
|
||||
"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",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -76,7 +76,7 @@ class Neo4jDataAutoConfigurationTests {
|
||||
assertThat(context).hasSingleBean(org.neo4j.ogm.config.Configuration.class);
|
||||
assertThat(context).hasSingleBean(SessionFactory.class);
|
||||
assertThat(context).hasSingleBean(Neo4jTransactionManager.class);
|
||||
assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class);
|
||||
assertThat(context).doesNotHaveBean(OpenSessionInViewInterceptor.class);
|
||||
assertThat(context).doesNotHaveBean(BookmarkManager.class);
|
||||
});
|
||||
}
|
||||
@@ -105,7 +105,7 @@ class Neo4jDataAutoConfigurationTests {
|
||||
assertThat(context).hasSingleBean(SessionFactory.class);
|
||||
assertThat(context.getBean(SessionFactory.class)).isSameAs(context.getBean("customSessionFactory"));
|
||||
assertThat(context).hasSingleBean(Neo4jTransactionManager.class);
|
||||
assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class);
|
||||
assertThat(context).doesNotHaveBean(OpenSessionInViewInterceptor.class);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -136,9 +136,9 @@ class Neo4jDataAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void openSessionInViewInterceptorCanBeDisabled() {
|
||||
this.contextRunner.withPropertyValues("spring.data.neo4j.open-in-view:false")
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(OpenSessionInViewInterceptor.class));
|
||||
void openSessionInViewInterceptorCanBeEnabled() {
|
||||
this.contextRunner.withPropertyValues("spring.data.neo4j.open-in-view:true")
|
||||
.run((context) -> assertThat(context).hasSingleBean(OpenSessionInViewInterceptor.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user