From 61c931943f19f96db1c0b21e1563a56a116f77d8 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 28 Dec 2016 14:15:09 -0800 Subject: [PATCH 1/2] Fix Devtools PatternResolver Servlet support Update ClassLoaderFilesResourcePatternResolver to support servlet resources when it's being used with a WebApplicationContext. Prior to commit 918e122ddc a `ResourceLoader` was not added to the `ApplicationContext`, meaning that servlet resources could be found by virtue of the protected `getResourceByPath()` method. Following commit 918e122ddc, the context `ResourceLoader` is set, meaning that all calls to `getResource` delegate to the `ResourceLoader` and the `ApplicationContext` methods are not invoked. Since the devtools `ResourceLoader` wasn't Servlet aware, servlet resources could not be found. Fixes gh-7752 --- ...assLoaderFilesResourcePatternResolver.java | 86 ++++++++++++- .../boot/devtools/restart/Restarter.java | 6 +- ...aderFilesResourcePatternResolverTests.java | 120 ++++++++++++++++++ .../spring-boot-sample-war/pom.xml | 7 + 4 files changed, 213 insertions(+), 6 deletions(-) create mode 100644 spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolverTests.java diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java index 51f24e31314..64e1ea1b4f2 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java @@ -29,32 +29,54 @@ import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kin import org.springframework.boot.devtools.restart.classloader.ClassLoaderFileURLStreamHandler; import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles; import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceFolder; +import org.springframework.context.ApplicationContext; import org.springframework.core.io.AbstractResource; +import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.UrlResource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.util.AntPathMatcher; +import org.springframework.util.ClassUtils; +import org.springframework.util.PathMatcher; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.ServletContextResource; +import org.springframework.web.context.support.ServletContextResourcePatternResolver; /** * A {@code ResourcePatternResolver} that considers {@link ClassLoaderFiles} when * resolving resources. * * @author Andy Wilkinson + * @author Phillip Webb */ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternResolver { private static final String[] LOCATION_PATTERN_PREFIXES = { CLASSPATH_ALL_URL_PREFIX, CLASSPATH_URL_PREFIX }; - private final ResourcePatternResolver delegate = new PathMatchingResourcePatternResolver(); + private static final String WEB_CONTEXT_CLASS = "org.springframework.web.context." + + "WebApplicationContext"; - private final AntPathMatcher antPathMatcher = new AntPathMatcher(); + private final ResourcePatternResolver delegate; + + private final PathMatcher antPathMatcher = new AntPathMatcher(); private final ClassLoaderFiles classLoaderFiles; - ClassLoaderFilesResourcePatternResolver(ClassLoaderFiles classLoaderFiles) { + ClassLoaderFilesResourcePatternResolver(ApplicationContext applicationContext, + ClassLoaderFiles classLoaderFiles) { this.classLoaderFiles = classLoaderFiles; + this.delegate = getResourcePatternResolverFactory() + .getResourcePatternResolver(applicationContext); + } + + private ResourcePatternResolverFactory getResourcePatternResolverFactory() { + if (ClassUtils.isPresent(WEB_CONTEXT_CLASS, null)) { + return new WebResourcePatternResolverFactory(); + } + return new ResourcePatternResolverFactory(); } @Override @@ -137,7 +159,7 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe * A {@link Resource} that represents a {@link ClassLoaderFile} that has been * {@link Kind#DELETED deleted}. */ - private final class DeletedClassLoaderFileResource extends AbstractResource { + static final class DeletedClassLoaderFileResource extends AbstractResource { private final String name; @@ -162,4 +184,60 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe } + /** + * Factory used to create the {@link ResourcePatternResolver} delegate. + */ + private static class ResourcePatternResolverFactory { + + public ResourcePatternResolver getResourcePatternResolver( + ApplicationContext applicationContext) { + return new PathMatchingResourcePatternResolver(); + } + + } + + /** + * {@link ResourcePatternResolverFactory} to be used when the classloader can access + * {@link WebApplicationContext}. + */ + private static class WebResourcePatternResolverFactory + extends ResourcePatternResolverFactory { + + @Override + public ResourcePatternResolver getResourcePatternResolver( + ApplicationContext applicationContext) { + if (applicationContext instanceof WebApplicationContext) { + return new ServletContextResourcePatternResolver( + new WebApplicationContextResourceLoader( + (WebApplicationContext) applicationContext)); + } + return super.getResourcePatternResolver(applicationContext); + } + + } + + /** + * {@link ResourceLoader} that optionally supports {@link ServletContextResource + * ServletContextResources}. + */ + private static class WebApplicationContextResourceLoader + extends DefaultResourceLoader { + + private final WebApplicationContext applicationContext; + + WebApplicationContextResourceLoader(WebApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + @Override + protected Resource getResourceByPath(String path) { + if (this.applicationContext.getServletContext() != null) { + return new ServletContextResource( + this.applicationContext.getServletContext(), path); + } + return super.getResourceByPath(path); + } + + } + } diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java index c66d9bb8faa..04306f2761d 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java @@ -51,6 +51,7 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -426,8 +427,9 @@ public class Restarter { } private void prepare(GenericApplicationContext applicationContext) { - applicationContext.setResourceLoader( - new ClassLoaderFilesResourcePatternResolver(this.classLoaderFiles)); + ResourceLoader resourceLoader = new ClassLoaderFilesResourcePatternResolver( + applicationContext, this.classLoaderFiles); + applicationContext.setResourceLoader(resourceLoader); } private LeakSafeThread getLeakSafeThread() { diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolverTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolverTests.java new file mode 100644 index 00000000000..c709ef822b4 --- /dev/null +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolverTests.java @@ -0,0 +1,120 @@ +/* + * Copyright 2012-2016 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.devtools.restart; + +import java.io.File; +import java.io.IOException; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import org.springframework.boot.devtools.restart.ClassLoaderFilesResourcePatternResolver.DeletedClassLoaderFileResource; +import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile; +import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind; +import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles; +import org.springframework.context.support.GenericApplicationContext; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.mock.web.MockServletContext; +import org.springframework.util.FileCopyUtils; +import org.springframework.web.context.support.GenericWebApplicationContext; +import org.springframework.web.context.support.ServletContextResource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link ClassLoaderFilesResourcePatternResolver}. + * + * @author Phillip Webb + */ +public class ClassLoaderFilesResourcePatternResolverTests { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + private ClassLoaderFiles files; + + private ClassLoaderFilesResourcePatternResolver resolver; + + @Before + public void setup() { + this.files = new ClassLoaderFiles(); + this.resolver = new ClassLoaderFilesResourcePatternResolver( + new GenericApplicationContext(), this.files); + } + + @Test + public void getClassLoaderShouldReturnClassLoader() throws Exception { + assertThat(this.resolver.getClassLoader()).isNotNull(); + } + + @Test + public void getResourceShouldReturnResource() throws Exception { + Resource resource = this.resolver.getResource("index.html"); + assertThat(resource).isNotNull().isInstanceOf(ClassPathResource.class); + } + + @Test + public void getResourceWhenHasServeletContextShouldReturnServletResource() + throws Exception { + GenericWebApplicationContext context = new GenericWebApplicationContext( + new MockServletContext()); + this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files); + Resource resource = this.resolver.getResource("index.html"); + assertThat(resource).isNotNull().isInstanceOf(ServletContextResource.class); + } + + @Test + public void getResourceWhenDeletedShouldReturnDeletedResource() throws Exception { + File folder = this.temp.newFolder(); + File file = createFile(folder, "name.class"); + this.files.addFile(folder.getName(), "name.class", + new ClassLoaderFile(Kind.DELETED, null)); + Resource resource = this.resolver.getResource("file:" + file.getAbsolutePath()); + assertThat(resource).isNotNull() + .isInstanceOf(DeletedClassLoaderFileResource.class); + } + + @Test + public void getResourcesShouldReturnResources() throws Exception { + File folder = this.temp.newFolder(); + createFile(folder, "name.class"); + Resource[] resources = this.resolver + .getResources("file:" + folder.getAbsolutePath() + "/**"); + assertThat(resources).isNotEmpty(); + } + + @Test + public void getResourcesWhenDeletedShouldFilterDeleted() throws Exception { + File folder = this.temp.newFolder(); + createFile(folder, "name.class"); + this.files.addFile(folder.getName(), "name.class", + new ClassLoaderFile(Kind.DELETED, null)); + Resource[] resources = this.resolver + .getResources("file:" + folder.getAbsolutePath() + "/**"); + assertThat(resources).isEmpty(); + } + + private File createFile(File folder, String name) throws IOException { + File file = new File(folder, name); + FileCopyUtils.copy("test".getBytes(), file); + return file; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-war/pom.xml b/spring-boot-samples/spring-boot-sample-war/pom.xml index fee8d09f598..7a44a9cdfb2 100644 --- a/spring-boot-samples/spring-boot-sample-war/pom.xml +++ b/spring-boot-samples/spring-boot-sample-war/pom.xml @@ -42,6 +42,13 @@ + + + org.springframework.boot + spring-boot-devtools + provided + + org.springframework.boot spring-boot-starter-test From 8b69856fc9b55bc167299d80281dd0f21ab79e9d Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 28 Dec 2016 15:23:26 -0800 Subject: [PATCH 2/2] Polish --- .../autoconfigure/CrshAutoConfiguration.java | 2 +- .../MetricRepositoryAutoConfiguration.java | 5 +++-- .../autoconfigure/ShellProperties.java | 2 +- .../repository/InMemoryMetricRepository.java | 6 +++--- .../InMemoryMultiMetricRepository.java | 19 +++++++++++++++---- .../JolokiaAutoConfigurationTests.java | 2 +- .../PrefixMetricGroupExporterTests.java | 14 ++++++-------- .../InMemoryMetricRepositoryTests.java | 2 ++ .../InMemoryMultiMetricRepositoryTests.java | 5 +++-- .../cassandra/ClusterBuilderCustomizer.java | 6 ++++-- .../condition/SearchStrategy.java | 2 +- .../jdbc/DataSourceConfiguration.java | 2 +- .../livereload/LiveReloadServerTests.java | 3 --- ...terDeprecatedWarningAutoConfiguration.java | 2 +- .../orm/jpa/AutoConfigureTestDatabase.java | 2 +- .../test/context/SpringBootContextLoader.java | 15 +++++++++++---- .../SpringBootTestCustomPortTests.java | 4 ++-- ...bEnvironmentRandomPortCustomPortTests.java | 4 +++- .../plugin/DeprecatedSpringBootPlugin.java | 2 +- ...TomcatEmbeddedServletContainerFactory.java | 2 +- .../event/ApplicationStartedEvent.java | 2 +- .../logging/LoggingApplicationListener.java | 2 ++ 22 files changed, 64 insertions(+), 41 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java index 719a8884f3a..133c51d6a2c 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java @@ -115,7 +115,7 @@ import org.springframework.util.StringUtils; * @author Christian Dupuis * @author Matt Benson * @see ShellProperties - * @deprecated as of 1.5 + * @deprecated as of 1.5 since CRaSH is not actively maintained */ @Configuration @ConditionalOnClass(PluginLifeCycle.class) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfiguration.java index ca4e123c829..80d6bcf2938 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfiguration.java @@ -158,8 +158,9 @@ public class MetricRepositoryAutoConfiguration { @Bean @ExportMetricReader @ActuatorMetricWriter - public InMemoryMultiMetricRepository actuatorMultiMetricRepository() { - return new InMemoryMultiMetricRepository(actuatorMetricRepository()); + public InMemoryMultiMetricRepository actuatorMultiMetricRepository( + InMemoryMetricRepository actuatorMetricRepository) { + return new InMemoryMultiMetricRepository(actuatorMetricRepository); } } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java index f60e7458332..91fe9665f4b 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java @@ -38,7 +38,7 @@ import org.springframework.util.StringUtils; * @author Phillip Webb * @author Eddú Meléndez * @author Stephane Nicoll - * @deprecated as of 1.5 + * @deprecated as of 1.5 since CRaSH is not actively maintained */ @ConfigurationProperties(prefix = ShellProperties.SHELL_PREFIX, ignoreUnknownFields = true) @Deprecated diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepository.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepository.java index 8e5d7b82203..bf0d243ac91 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepository.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepository.java @@ -44,16 +44,16 @@ public class InMemoryMetricRepository implements MetricRepository { final int amount = delta.getValue().intValue(); final Date timestamp = delta.getTimestamp(); this.metrics.update(metricName, new Callback>() { + @Override public Metric modify(Metric current) { if (current != null) { return new Metric(metricName, current.increment(amount).getValue(), timestamp); } - else { - return new Metric(metricName, (long) amount, timestamp); - } + return new Metric(metricName, (long) amount, timestamp); } + }); } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/InMemoryMultiMetricRepository.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/InMemoryMultiMetricRepository.java index e3a4640fc46..73a048d59f0 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/InMemoryMultiMetricRepository.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/InMemoryMultiMetricRepository.java @@ -22,6 +22,7 @@ import java.util.HashSet; import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.writer.Delta; +import org.springframework.util.Assert; /** * {@link MultiMetricRepository} implementation backed by a @@ -36,14 +37,24 @@ public class InMemoryMultiMetricRepository implements MultiMetricRepository { private final Collection groups = new HashSet(); - public InMemoryMultiMetricRepository(InMemoryMetricRepository repository) { - this.repository = repository; - } - + /** + * Create a new {@link InMemoryMetricRepository} backed by a new + * {@link InMemoryMetricRepository}. + */ public InMemoryMultiMetricRepository() { this(new InMemoryMetricRepository()); } + /** + * Create a new {@link InMemoryMetricRepository} backed by the specified + * {@link InMemoryMetricRepository}. + * @param repository the backing repository + */ + public InMemoryMultiMetricRepository(InMemoryMetricRepository repository) { + Assert.notNull(repository, "Repository must not be null"); + this.repository = repository; + } + @Override public void set(String group, Collection> values) { String prefix = group; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java index 0613caaba4f..f70f110ccac 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java @@ -145,7 +145,7 @@ public class JolokiaAutoConfigurationTests { Collection endpoints) { EndpointHandlerMapping mapping = new EndpointHandlerMapping(endpoints); mapping.setSecurityInterceptor( - new MvcEndpointSecurityInterceptor(false, Collections.EMPTY_LIST)); + new MvcEndpointSecurityInterceptor(false, Collections.emptyList())); return mapping; } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporterTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporterTests.java index 959889c797c..04ac5559407 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporterTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporterTests.java @@ -54,8 +54,8 @@ public class PrefixMetricGroupExporterTests { @Test public void countersIncremented() { this.writer.increment("counter.foo", new Delta("bar", 1L)); - this.reader.set("counter", Collections.>singletonList( - new Metric("counter.foo.bar", 1))); + this.reader.set("counter", Collections + .>singletonList(new Metric("counter.foo.bar", 1))); this.exporter.setGroups(Collections.singleton("counter.foo")); this.exporter.export(); assertThat(this.writer.findAll("counter.foo").iterator().next().getValue()) @@ -65,8 +65,7 @@ public class PrefixMetricGroupExporterTests { @Test public void unprefixedMetricsNotCopied() { this.reader.set("foo", Arrays.>asList( - new Metric("foo.bar", 2.3), - new Metric("foo.spam", 1.3))); + new Metric("foo.bar", 2.3), new Metric("foo.spam", 1.3))); this.exporter.setGroups(Collections.singleton("bar")); this.exporter.export(); assertThat(Iterables.collection(this.writer.groups())).isEmpty(); @@ -84,10 +83,9 @@ public class PrefixMetricGroupExporterTests { @Test public void onlyPrefixedMetricsCopied() { this.reader.set("foo", Arrays.>asList( - new Metric("foo.bar", 2.3), - new Metric("foo.spam", 1.3))); - this.reader.set("foobar", Collections.>singletonList( - new Metric("foobar.spam", 1.3))); + new Metric("foo.bar", 2.3), new Metric("foo.spam", 1.3))); + this.reader.set("foobar", Collections + .>singletonList(new Metric("foobar.spam", 1.3))); this.exporter.setGroups(Collections.singleton("foo")); this.exporter.export(); assertThat(Iterables.collection(this.writer.groups())).hasSize(1); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepositoryTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepositoryTests.java index d571b618b0f..a3212779f3d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepositoryTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryMetricRepositoryTests.java @@ -28,6 +28,8 @@ import static org.assertj.core.api.Assertions.offset; /** * Tests for {@link InMemoryMetricRepository}. + * + * @author Dave Syer */ public class InMemoryMetricRepositoryTests { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryMultiMetricRepositoryTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryMultiMetricRepositoryTests.java index 38214e9971f..19bac157fa6 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryMultiMetricRepositoryTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/repository/InMemoryMultiMetricRepositoryTests.java @@ -29,12 +29,13 @@ import org.springframework.boot.actuate.metrics.writer.Delta; import static org.assertj.core.api.Assertions.assertThat; /** + * Tests for {@link InMemoryMultiMetricRepository}. + * * @author Dave Syer */ public class InMemoryMultiMetricRepositoryTests { - private final InMemoryMultiMetricRepository repository = - new InMemoryMultiMetricRepository(); + private final InMemoryMultiMetricRepository repository = new InMemoryMultiMetricRepository(); @Test public void registeredPrefixCounted() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/ClusterBuilderCustomizer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/ClusterBuilderCustomizer.java index 5bb8cd6c37b..15b803402b0 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/ClusterBuilderCustomizer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/ClusterBuilderCustomizer.java @@ -20,7 +20,9 @@ import com.datastax.driver.core.Cluster; /** * Callback interface that can be implemented by beans wishing to customize the - * {@link Cluster} via {@link Cluster.Builder} retaining its default auto-configuration. + * {@link com.datastax.driver.core.Cluster} via + * {@link com.datastax.driver.core.Cluster.Builder} retaining its default + * auto-configuration. * * @author Eddú Meléndez * @since 1.5.0 @@ -28,7 +30,7 @@ import com.datastax.driver.core.Cluster; public interface ClusterBuilderCustomizer { /** - * Customize the {@link Cluster.Builder}. + * Customize the {@link com.datastax.driver.core.Cluster.Builder}. * @param clusterBuilder the builder to customize */ void customize(Cluster.Builder clusterBuilder); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/SearchStrategy.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/SearchStrategy.java index eeb9d29fe52..3b3cb7f8199 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/SearchStrategy.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/SearchStrategy.java @@ -30,7 +30,7 @@ public enum SearchStrategy { /** * Search all parents and ancestors, but not the current context. - * @deprecated since 1.5 in favor of {@link SearchStrategy#ANCESTORS} + * @deprecated as of 1.5 in favor of {@link SearchStrategy#ANCESTORS} */ @Deprecated PARENTS, diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java index 1f1a3d08db5..e94c6c01633 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration.java @@ -85,7 +85,7 @@ abstract class DataSourceConfiguration { /** * DBCP DataSource configuration. * - * @deprecated as of Spring Boot 1.5 in favor of DBCP2 + * @deprecated as of 1.5 in favor of DBCP2 */ @ConditionalOnClass(org.apache.commons.dbcp.BasicDataSource.class) @ConditionalOnProperty(name = "spring.datasource.type", havingValue = "org.apache.commons.dbcp.BasicDataSource", matchIfMissing = true) diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java index ae724388bb4..79df32a07f8 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/livereload/LiveReloadServerTests.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URI; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -57,8 +56,6 @@ public class LiveReloadServerTests { private static final String HANDSHAKE = "{command: 'hello', " + "protocols: ['http://livereload.com/protocols/official-7']}"; - private static final ByteBuffer NO_DATA = ByteBuffer.allocate(0); - private int port = SocketUtils.findAvailableTcpPort(); private MonitoredLiveReloadServer server; diff --git a/spring-boot-starters/spring-boot-starter-remote-shell/src/main/java/org/springframework/boot/starter/remote/shell/RemoteShellStarterDeprecatedWarningAutoConfiguration.java b/spring-boot-starters/spring-boot-starter-remote-shell/src/main/java/org/springframework/boot/starter/remote/shell/RemoteShellStarterDeprecatedWarningAutoConfiguration.java index b851c652649..3d8af3877fa 100644 --- a/spring-boot-starters/spring-boot-starter-remote-shell/src/main/java/org/springframework/boot/starter/remote/shell/RemoteShellStarterDeprecatedWarningAutoConfiguration.java +++ b/spring-boot-starters/spring-boot-starter-remote-shell/src/main/java/org/springframework/boot/starter/remote/shell/RemoteShellStarterDeprecatedWarningAutoConfiguration.java @@ -40,7 +40,7 @@ public class RemoteShellStarterDeprecatedWarningAutoConfiguration { @PostConstruct public void logWarning() { - logger.warn("spring-boot-starter-remote-shell is deprecated since Spring Boot " + logger.warn("spring-boot-starter-remote-shell is deprecated as of Spring Boot " + "1.5 and will be removed in Spring Boot 2.0"); } diff --git a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/AutoConfigureTestDatabase.java b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/AutoConfigureTestDatabase.java index 09a827065d0..cf6951c98bb 100644 --- a/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/AutoConfigureTestDatabase.java +++ b/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/AutoConfigureTestDatabase.java @@ -34,7 +34,7 @@ import org.springframework.boot.test.autoconfigure.properties.PropertyMapping; * instead of any application defined or auto-configured {@link DataSource}. * * @author Stephane Nicoll - * @deprecated since 1.5 in favour of + * @deprecated as of 1.5 in favor of * {@link org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase} */ @Target({ ElementType.TYPE, ElementType.METHOD }) diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java index 6531324c350..f49bbf955e3 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java @@ -38,6 +38,7 @@ import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertySources; import org.springframework.core.env.PropertySourcesPropertyResolver; import org.springframework.core.env.StandardEnvironment; import org.springframework.core.io.DefaultResourceLoader; @@ -160,15 +161,21 @@ public class SpringBootContextLoader extends AbstractContextLoader { } private boolean hasCustomServerPort(List properties) { - Map props = TestPropertySourceUtils.convertInlinedPropertiesToMap( - properties.toArray(new String[properties.size()])); - MutablePropertySources sources = new MutablePropertySources(); - sources.addFirst(new MapPropertySource("inline", props)); + PropertySources sources = convertToPropertySources(properties); RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( new PropertySourcesPropertyResolver(sources), "server."); return resolver.containsProperty("port"); } + private PropertySources convertToPropertySources(List properties) { + Map source = TestPropertySourceUtils + .convertInlinedPropertiesToMap( + properties.toArray(new String[properties.size()])); + MutablePropertySources sources = new MutablePropertySources(); + sources.addFirst(new MapPropertySource("inline", source)); + return sources; + } + private List> getInitializers( MergedContextConfiguration config, SpringApplication application) { List> initializers = new ArrayList>(); diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestCustomPortTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestCustomPortTests.java index 4d50efa1e67..0ae8386da3e 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestCustomPortTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestCustomPortTests.java @@ -27,8 +27,8 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; /** - * Test for {@link SpringBootTest} with a custom inline server.port in a non-embedded - * web environment. + * Test for {@link SpringBootTest} with a custom inline server.port in a non-embedded web + * environment. * * @author Stephane Nicoll */ diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentRandomPortCustomPortTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentRandomPortCustomPortTests.java index f8e439ba058..e216dc8ab45 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentRandomPortCustomPortTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentRandomPortCustomPortTests.java @@ -38,7 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringRunner.class) @DirtiesContext -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "server.port=12345" }) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "server.port=12345" }) public class SpringBootTestWebEnvironmentRandomPortCustomPortTests { @Autowired @@ -55,4 +56,5 @@ public class SpringBootTestWebEnvironmentRandomPortCustomPortTests { protected static class Config extends AbstractConfig { } + } diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/DeprecatedSpringBootPlugin.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/DeprecatedSpringBootPlugin.java index 65dc7d26977..9e4b806ce6d 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/DeprecatedSpringBootPlugin.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/DeprecatedSpringBootPlugin.java @@ -25,7 +25,7 @@ import org.slf4j.LoggerFactory; * to use the new Gradle Plugin Portal-compatible ID {@code org.springframework.boot}. * * @author Andy Wilkinson - * @deprecated since 1.4.2 in favor of {@link SpringBootPlugin} + * @deprecated as of 1.4.2 in favor of {@link SpringBootPlugin} */ @Deprecated public class DeprecatedSpringBootPlugin extends SpringBootPlugin { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java index c0cddd65f11..7f073b166bc 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java @@ -554,7 +554,7 @@ public class TomcatEmbeddedServletContainerFactory * A comma-separated list of jars to ignore for TLD scanning. See Tomcat's * catalina.properties for typical values. Defaults to a list drawn from that source. * @param tldSkip the jars to skip when scanning for TLDs etc - * @deprecated since 1.5.0 in favor of {@link #setTldSkipPatterns(Collection)} + * @deprecated as of 1.5 in favor of {@link #setTldSkipPatterns(Collection)} */ @Deprecated public void setTldSkip(String tldSkip) { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/event/ApplicationStartedEvent.java b/spring-boot/src/main/java/org/springframework/boot/context/event/ApplicationStartedEvent.java index f075302c2a3..0cfd63f25f1 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/event/ApplicationStartedEvent.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/event/ApplicationStartedEvent.java @@ -29,7 +29,7 @@ import org.springframework.core.env.Environment; * state too much at this early stage since it might be modified later in the lifecycle. * * @author Dave Syer - * @deprecated since 1.5.0 in favor of {@link ApplicationStartingEvent} + * @deprecated as of 1.5 in favor of {@link ApplicationStartingEvent} */ @Deprecated @SuppressWarnings("serial") diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java index 737cf477263..dc934324c85 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java @@ -97,6 +97,7 @@ public class LoggingApplicationListener implements GenericApplicationListener { /** * The name of the Spring property that contains the directory where log files are * written. + * @deprecated as of 1.5 in favor of {@link LogFile#PATH_PROPERTY} */ @Deprecated public static final String PATH_PROPERTY = LogFile.PATH_PROPERTY; @@ -104,6 +105,7 @@ public class LoggingApplicationListener implements GenericApplicationListener { /** * The name of the Spring property that contains the name of the log file. Names can * be an exact location or relative to the current directory. + * @deprecated as of 1.5 in favor of {@link LogFile#FILE_PROPERTY} */ @Deprecated public static final String FILE_PROPERTY = LogFile.FILE_PROPERTY;