diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.java index 252a9d809a5..a5fe4717898 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.java @@ -59,7 +59,8 @@ public class ServletEndpointManagementContextConfiguration { private final ApplicationContext context; - public WebMvcServletEndpointManagementContextConfiguration(ApplicationContext context) { + public WebMvcServletEndpointManagementContextConfiguration( + ApplicationContext context) { this.context = context; } @@ -67,8 +68,12 @@ public class ServletEndpointManagementContextConfiguration { public ServletEndpointRegistrar servletEndpointRegistrar( WebEndpointProperties properties, ServletEndpointsSupplier servletEndpointsSupplier) { - DispatcherServletPathProvider servletPathProvider = this.context.getBean(DispatcherServletPathProvider.class); - String servletPath = (servletPathProvider.getServletPath().equals("/") ? "" : servletPathProvider.getServletPath()); + DispatcherServletPathProvider servletPathProvider = this.context + .getBean(DispatcherServletPathProvider.class); + String servletPath = servletPathProvider.getServletPath(); + if (servletPath.equals("/")) { + servletPath = ""; + } return new ServletEndpointRegistrar(servletPath + properties.getBasePath(), servletEndpointsSupplier.getEndpoints()); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitConnectionFactoryMetricsPostProcessor.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitConnectionFactoryMetricsPostProcessor.java index 23c8c438361..1f638c1742d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitConnectionFactoryMetricsPostProcessor.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitConnectionFactoryMetricsPostProcessor.java @@ -30,13 +30,12 @@ import org.springframework.util.StringUtils; /** * {@link BeanPostProcessor} that configures RabbitMQ metrics. Such arrangement is - * necessary because a connection can be eagerly created and cached without a reference - * to a proper {@link MetricsCollector}. + * necessary because a connection can be eagerly created and cached without a reference to + * a proper {@link MetricsCollector}. * * @author Stephane Nicoll */ -class RabbitConnectionFactoryMetricsPostProcessor - implements BeanPostProcessor, Ordered { +class RabbitConnectionFactoryMetricsPostProcessor implements BeanPostProcessor, Ordered { private static final String CONNECTION_FACTORY_SUFFIX = "connectionFactory"; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequest.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequest.java index c79bb7e3ebc..000032a209a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequest.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/reactive/EndpointRequest.java @@ -219,7 +219,8 @@ public final class EndpointRequest { } private String getEndpointId(Class source) { - Endpoint annotation = AnnotatedElementUtils.getMergedAnnotation(source, Endpoint.class); + Endpoint annotation = AnnotatedElementUtils.getMergedAnnotation(source, + Endpoint.class); Assert.state(annotation != null, () -> "Class " + source + " is not annotated with @Endpoint"); return annotation.id(); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java index 042d556483e..3509740e404 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java @@ -238,7 +238,8 @@ public final class EndpointRequest { } private String getEndpointId(Class source) { - Endpoint annotation = AnnotatedElementUtils.getMergedAnnotation(source, Endpoint.class); + Endpoint annotation = AnnotatedElementUtils.getMergedAnnotation(source, + Endpoint.class); Assert.state(annotation != null, () -> "Class " + source + " is not annotated with @Endpoint"); return annotation.id(); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfigurationTests.java index a0a78984e9b..2c3c037458a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfigurationTests.java @@ -49,12 +49,11 @@ public class ServletEndpointManagementContextConfigurationTests { @Test public void contextShouldContainServletEndpointRegistrar() { - FilteredClassLoader classLoader = new FilteredClassLoader( - ResourceConfig.class); + FilteredClassLoader classLoader = new FilteredClassLoader(ResourceConfig.class); this.contextRunner.withClassLoader(classLoader).run((context) -> { - assertThat(context) - .hasSingleBean(ServletEndpointRegistrar.class); - ServletEndpointRegistrar bean = context.getBean(ServletEndpointRegistrar.class); + assertThat(context).hasSingleBean(ServletEndpointRegistrar.class); + ServletEndpointRegistrar bean = context + .getBean(ServletEndpointRegistrar.class); String basePath = (String) ReflectionTestUtils.getField(bean, "basePath"); assertThat(basePath).isEqualTo("/test/actuator"); }); @@ -65,9 +64,9 @@ public class ServletEndpointManagementContextConfigurationTests { FilteredClassLoader classLoader = new FilteredClassLoader( DispatcherServlet.class); this.contextRunner.withClassLoader(classLoader).run((context) -> { - assertThat(context) - .hasSingleBean(ServletEndpointRegistrar.class); - ServletEndpointRegistrar bean = context.getBean(ServletEndpointRegistrar.class); + assertThat(context).hasSingleBean(ServletEndpointRegistrar.class); + ServletEndpointRegistrar bean = context + .getBean(ServletEndpointRegistrar.class); String basePath = (String) ReflectionTestUtils.getField(bean, "basePath"); assertThat(basePath).isEqualTo("/actuator"); }); diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java index 327b1e17dc3..7d1c38bf647 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/EndpointMBean.java @@ -72,7 +72,6 @@ public class EndpointMBean implements DynamicMBean { this.operations = getOperations(endpoint); } - private Map getOperations(ExposableJmxEndpoint endpoint) { Map operations = new HashMap<>(); endpoint.getOperations() @@ -94,7 +93,8 @@ public class EndpointMBean implements DynamicMBean { + "' has no operation named " + actionName; throw new ReflectionException(new IllegalArgumentException(message), message); } - ClassLoader previousClassLoader = overrideThreadContextClassLoader(this.classLoader); + ClassLoader previousClassLoader = overrideThreadContextClassLoader( + this.classLoader); try { return invoke(operation, params); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthAggregator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthAggregator.java index 98140ce83d5..f5525e60d39 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthAggregator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractHealthAggregator.java @@ -33,8 +33,8 @@ public abstract class AbstractHealthAggregator implements HealthAggregator { @Override public final Health aggregate(Map healths) { - List statusCandidates = healths.values().stream() - .map(Health::getStatus).collect(Collectors.toList()); + List statusCandidates = healths.values().stream().map(Health::getStatus) + .collect(Collectors.toList()); Status status = aggregateStatus(statusCandidates); Map details = aggregateDetails(healths); return new Health.Builder(status, details).build(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/RepositoryType.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/RepositoryType.java index 88dddc5a370..c1dbaf2071a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/RepositoryType.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/RepositoryType.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java index 857d3e7d4d2..0772418c795 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -64,26 +64,28 @@ public class FreeMarkerAutoConfiguration { @PostConstruct public void checkTemplateLocationExists() { - if (logger.isWarnEnabled()) { - if (this.properties.isCheckTemplateLocation()) { - TemplateLocation templatePathLocation = null; - List locations = new ArrayList<>(); - for (String templateLoaderPath : this.properties.getTemplateLoaderPath()) { - TemplateLocation location = new TemplateLocation(templateLoaderPath); - locations.add(location); - if (location.exists(this.applicationContext)) { - templatePathLocation = location; - break; - } - } - if (templatePathLocation == null) { - logger.warn("Cannot find template location(s): " + locations - + " (please add some templates, " - + "check your FreeMarker configuration, or set " - + "spring.freemarker.checkTemplateLocation=false)"); - } + if (logger.isWarnEnabled() && this.properties.isCheckTemplateLocation()) { + List locations = getLocations(); + if (locations.stream().noneMatch(this::locationExists)) { + logger.warn("Cannot find template location(s): " + locations + + " (please add some templates, " + + "check your FreeMarker configuration, or set " + + "spring.freemarker.checkTemplateLocation=false)"); } } } + private List getLocations() { + List locations = new ArrayList<>(); + for (String templateLoaderPath : this.properties.getTemplateLoaderPath()) { + TemplateLocation location = new TemplateLocation(templateLoaderPath); + locations.add(location); + } + return locations; + } + + private boolean locationExists(TemplateLocation location) { + return location.exists(this.applicationContext); + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializerTests.java index a01c136a23d..83b5702c891 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializerTests.java @@ -51,14 +51,13 @@ public class QuartzDataSourceInitializerTests { @Test public void commentPrefixCanBeCustomized() { this.contextRunner.withUserConfiguration(TestConfiguration.class) - .withPropertyValues( - "spring.quartz.jdbc.comment-prefix=##", + .withPropertyValues("spring.quartz.jdbc.comment-prefix=##", "spring.quartz.jdbc.schema=classpath:org/springframework/boot/autoconfigure/quartz/tables_@@platform@@.sql") .run((context) -> { JdbcTemplate jdbcTemplate = context.getBean(JdbcTemplate.class); assertThat(jdbcTemplate.queryForObject( "SELECT COUNT(*) FROM QRTZ_TEST_TABLE", Integer.class)) - .isEqualTo(0); + .isEqualTo(0); }); } @@ -69,7 +68,8 @@ public class QuartzDataSourceInitializerTests { @Bean public QuartzDataSourceInitializer initializer(DataSource dataSource, ResourceLoader resourceLoader, QuartzProperties properties) { - return new QuartzDataSourceInitializer(dataSource, resourceLoader, properties); + return new QuartzDataSourceInitializer(dataSource, resourceLoader, + properties); } } diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandlerTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandlerTests.java index d60e7bc90cf..78658b9ad3c 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandlerTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/LocalHostUriTemplateHandlerTests.java @@ -107,8 +107,8 @@ public class LocalHostUriTemplateHandlerTests { URI uri = URI.create("http://www.example.com"); given(uriTemplateHandler.expand("https://localhost:8080/", uriVariables)) .willReturn(uri); - LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler( - environment, "https", uriTemplateHandler); + LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(environment, + "https", uriTemplateHandler); assertThat(handler.expand("/", uriVariables)).isEqualTo(uri); verify(uriTemplateHandler).expand("https://localhost:8080/", uriVariables); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java index acb863437b0..1a9e6476c73 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java @@ -18,7 +18,6 @@ package org.springframework.boot.context.properties.bind; import java.lang.annotation.Annotation; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.TreeSet; import java.util.function.Supplier; @@ -83,24 +82,26 @@ abstract class IndexedElementsBinder extends AggregateBinder { ResolvableType aggregateType, ResolvableType elementType) { ConfigurationProperty property = source.getConfigurationProperty(root); if (property != null) { - Collection elements; - Object value = property.getValue(); - if (value instanceof String && !StringUtils.hasText((String) value)) { - elements = Collections.emptyList(); - } - else { - Object aggregate = convert(value, aggregateType, target.getAnnotations()); - ResolvableType collectionType = ResolvableType - .forClassWithGenerics(collection.get().getClass(), elementType); - elements = convert(aggregate, collectionType); - } - collection.get().addAll(elements); + bindValue(target, collection.get(), aggregateType, elementType, + property.getValue()); } else { bindIndexed(source, root, elementBinder, collection, elementType); } } + private void bindValue(Bindable target, Collection collection, + ResolvableType aggregateType, ResolvableType elementType, Object value) { + if (value instanceof String && !StringUtils.hasText((String) value)) { + return; + } + Object aggregate = convert(value, aggregateType, target.getAnnotations()); + ResolvableType collectionType = ResolvableType + .forClassWithGenerics(collection.getClass(), elementType); + Collection elements = convert(aggregate, collectionType); + collection.addAll(elements); + } + private void bindIndexed(ConfigurationPropertySource source, ConfigurationPropertyName root, AggregateElementBinder elementBinder, IndexedCollectionSupplier collection, ResolvableType elementType) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java index bba910fd333..a2bfeb9688a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletContextInitializerBeans.java @@ -79,8 +79,10 @@ public class ServletContextInitializerBeans this.initializers = new LinkedMultiValueMap<>(); addServletContextInitializerBeans(beanFactory); addAdaptableBeans(beanFactory); - List sortedInitializers = this.initializers.values().stream() - .flatMap(value -> value.stream().sorted(AnnotationAwareOrderComparator.INSTANCE)) + List sortedInitializers = this.initializers.values() + .stream() + .flatMap(value -> value.stream() + .sorted(AnnotationAwareOrderComparator.INSTANCE)) .collect(Collectors.toList()); this.sortedList = Collections.unmodifiableList(sortedInitializers); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/MockConfigurationPropertySource.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/MockConfigurationPropertySource.java index 11a4cd31996..e00d3c426ff 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/MockConfigurationPropertySource.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/MockConfigurationPropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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.