From 9159c87bf9f073810ac3da9a85292a9253d09985 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 10 Jan 2017 09:51:01 -0500 Subject: [PATCH 1/2] Polish --- .../rich/InMemoryRichGaugeRepository.java | 10 ++--- ...stractEmbeddedServletContainerFactory.java | 2 +- .../TomcatEmbeddedWebappClassLoader.java | 41 ++++++++----------- 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/rich/InMemoryRichGaugeRepository.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/rich/InMemoryRichGaugeRepository.java index 510eaf02ca..d80eb5aa34 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/rich/InMemoryRichGaugeRepository.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/rich/InMemoryRichGaugeRepository.java @@ -41,22 +41,20 @@ public class InMemoryRichGaugeRepository implements RichGaugeRepository { @Override public void set(Metric metric) { - final String name = metric.getName(); final double value = metric.getValue().doubleValue(); this.repository.update(name, new Callback() { + @Override public RichGauge modify(RichGauge current) { if (current == null) { - current = new RichGauge(name, value); - } - else { - current.set(value); + return new RichGauge(name, value); } + current.set(value); return current; } - }); + }); } @Override diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java index e870db7638..37efcc1ede 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java @@ -115,7 +115,7 @@ public abstract class AbstractEmbeddedServletContainerFactory private File getCommonDocumentRoot() { for (String commonDocRoot : COMMON_DOC_ROOTS) { File root = new File(commonDocRoot); - if (root != null && root.exists() && root.isDirectory()) { + if (root.exists() && root.isDirectory()) { return root.getAbsoluteFile(); } } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedWebappClassLoader.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedWebappClassLoader.java index d26685acd8..4406d450af 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedWebappClassLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedWebappClassLoader.java @@ -46,35 +46,28 @@ public class TomcatEmbeddedWebappClassLoader extends WebappClassLoader { @Override public synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - Class resultClass = null; + Class result = findExistingLoadedClass(name); + result = (result == null ? doLoadClass(name) : result); + if (result == null) { + throw new ClassNotFoundException(name); + } + return resolveIfNecessary(result, resolve); + } - // Check local class caches - resultClass = (resultClass == null ? findLoadedClass0(name) : resultClass); + private Class findExistingLoadedClass(String name) { + Class resultClass = findLoadedClass0(name); resultClass = (resultClass == null ? findLoadedClass(name) : resultClass); - if (resultClass != null) { - return resolveIfNecessary(resultClass, resolve); - } + return resultClass; + } - // Check security + private Class doLoadClass(String name) throws ClassNotFoundException { checkPackageAccess(name); - - // Perform the actual load - boolean delegateLoad = (this.delegate || filter(name, true)); - - if (delegateLoad) { - resultClass = (resultClass == null ? loadFromParent(name) : resultClass); - } - resultClass = (resultClass == null ? findClassIgnoringNotFound(name) - : resultClass); - if (!delegateLoad) { - resultClass = (resultClass == null ? loadFromParent(name) : resultClass); - } - - if (resultClass == null) { - throw new ClassNotFoundException(name); + if ((this.delegate || filter(name, true))) { + Class result = loadFromParent(name); + return (result == null ? findClassIgnoringNotFound(name) : result); } - - return resolveIfNecessary(resultClass, resolve); + Class result = findClassIgnoringNotFound(name); + return (result == null ? loadFromParent(name) : result); } private Class resolveIfNecessary(Class resultClass, boolean resolve) { From 65025d8dab7635ddc8f7f2ac48f04ef9ad2b71d2 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 10 Jan 2017 17:04:19 -0500 Subject: [PATCH 2/2] Enable Neo4J's open in view interceptor by default Closes gh-7943 --- .../data/neo4j/Neo4jDataAutoConfiguration.java | 2 +- .../data/neo4j/Neo4jDataAutoConfigurationTests.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java index 25ba2f8318..ed9b1961cb 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java @@ -120,7 +120,7 @@ public class Neo4jDataAutoConfiguration { @ConditionalOnClass({ WebMvcConfigurerAdapter.class, 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) protected static class Neo4jWebConfiguration { @Configuration diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java index c651987d8b..eed110b865 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfigurationTests.java @@ -78,7 +78,7 @@ public class Neo4jDataAutoConfigurationTests { assertThat(this.context.getBeansOfType(Neo4jOperations.class)).hasSize(1); assertThat(this.context.getBeansOfType(Neo4jTransactionManager.class)).hasSize(1); assertThat(this.context.getBeansOfType(OpenSessionInViewInterceptor.class)) - .isEmpty(); + .hasSize(1); } @Test @@ -131,10 +131,10 @@ public class Neo4jDataAutoConfigurationTests { } @Test - public void openSessionInViewInterceptorCanBeEnabled() { - load(null, "spring.data.neo4j.open-in-view=true"); + public void openSessionInViewInterceptorCanBeDisabled() { + load(null, "spring.data.neo4j.open-in-view:false"); assertThat(this.context.getBeansOfType(OpenSessionInViewInterceptor.class)) - .hasSize(1); + .isEmpty(); } @Test