diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryActuatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryActuatorAutoConfiguration.java index 86f6e0227b..fefe9b801d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryActuatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryActuatorAutoConfiguration.java @@ -22,6 +22,7 @@ import org.springframework.boot.actuate.autoconfigure.endpoint.DefaultCachingCon import org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextAutoConfiguration; import org.springframework.boot.actuate.endpoint.ParameterMapper; import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes; +import org.springframework.boot.actuate.endpoint.web.EndpointPathResolver; import org.springframework.boot.actuate.endpoint.web.annotation.WebAnnotationEndpointDiscoverer; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -82,7 +83,7 @@ public class CloudFoundryActuatorAutoConfiguration { RestTemplateBuilder builder) { WebAnnotationEndpointDiscoverer endpointDiscoverer = new WebAnnotationEndpointDiscoverer( this.applicationContext, parameterMapper, cachingConfigurationFactory, - endpointMediaTypes, (id) -> id); + endpointMediaTypes, EndpointPathResolver.useEndpointId()); return new CloudFoundryWebEndpointServletHandlerMapping( new EndpointMapping("/cloudfoundryapplication"), endpointDiscoverer.discoverEndpoints(), endpointMediaTypes, @@ -142,7 +143,6 @@ public class CloudFoundryActuatorAutoConfiguration { @Override public void configure(WebSecurity builder) throws Exception { - } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/DefaultEndpointPathResolver.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/DefaultEndpointPathResolver.java index ef521532f3..66ff39d9d5 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/DefaultEndpointPathResolver.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/DefaultEndpointPathResolver.java @@ -20,8 +20,8 @@ import org.springframework.boot.actuate.endpoint.web.EndpointPathResolver; import org.springframework.core.env.Environment; /** - * Default {@link EndpointPathResolver} implementation that use the - * {@link Environment} to determine if an endpoint has a custom path. + * Default {@link EndpointPathResolver} implementation that use the {@link Environment} to + * determine if an endpoint has a custom path. * * @author Stephane Nicoll */ diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.java index dbc01f49f1..4e3f4be5c1 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfiguration.java @@ -68,12 +68,11 @@ import org.springframework.integration.support.management.IntegrationManagementC @EnableConfigurationProperties(MetricsProperties.class) @Import({ MeterBindersConfiguration.class, WebMvcMetricsConfiguration.class, WebFluxMetricsConfiguration.class, RestTemplateMetricsConfiguration.class, - DataSourcePoolMetricsConfiguration.class, - AtlasExportConfiguration.class, DatadogExportConfiguration.class, - GangliaExportConfiguration.class, GraphiteExportConfiguration.class, - InfluxExportConfiguration.class, JmxExportConfiguration.class, - PrometheusExportConfiguration.class, SimpleExportConfiguration.class, - StatsdExportConfiguration.class }) + DataSourcePoolMetricsConfiguration.class, AtlasExportConfiguration.class, + DatadogExportConfiguration.class, GangliaExportConfiguration.class, + GraphiteExportConfiguration.class, InfluxExportConfiguration.class, + JmxExportConfiguration.class, PrometheusExportConfiguration.class, + SimpleExportConfiguration.class, StatsdExportConfiguration.class }) @AutoConfigureAfter(DataSourceAutoConfiguration.class) public class MetricsAutoConfiguration { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsConfiguration.java index 378c9eb180..4f882f1d6c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsConfiguration.java @@ -17,11 +17,13 @@ package org.springframework.boot.actuate.autoconfigure.metrics.jdbc; import java.util.Collection; +import java.util.List; import java.util.Map; import javax.sql.DataSource; import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Tags; import org.springframework.beans.factory.annotation.Autowired; @@ -62,12 +64,13 @@ public class DataSourcePoolMetricsConfiguration { @Autowired public void bindDataSourcesToRegistry(Map dataSources) { - for (Map.Entry entry : dataSources.entrySet()) { - String beanName = entry.getKey(); - DataSource dataSource = entry.getValue(); - new DataSourcePoolMetrics(dataSource, this.metadataProviders, this.metricName, - Tags.zip("name", getDataSourceName(beanName))).bindTo(this.registry); - } + dataSources.forEach(this::bindDataSourceToRegistry); + } + + private void bindDataSourceToRegistry(String beanName, DataSource dataSource) { + List tags = Tags.zip("name", getDataSourceName(beanName)); + new DataSourcePoolMetrics(dataSource, this.metadataProviders, this.metricName, + tags).bindTo(this.registry); } /** diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryActuatorAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryActuatorAutoConfigurationTests.java index 670ce82222..01f0e89089 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryActuatorAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryActuatorAutoConfigurationTests.java @@ -220,8 +220,7 @@ public class CloudFoundryActuatorAutoConfigurationTests { } @Test - public void endpointPathCustomizationIsNotApplied() - throws Exception { + public void endpointPathCustomizationIsNotApplied() throws Exception { TestPropertyValues.of("endpoints.test.web.path=another/custom") .applyTo(this.context); this.context.register(TestConfiguration.class); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryMvcWebEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryMvcWebEndpointIntegrationTests.java index 025701a9c6..09fbd90874 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryMvcWebEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryMvcWebEndpointIntegrationTests.java @@ -32,6 +32,7 @@ import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; import org.springframework.boot.actuate.endpoint.cache.CachingConfiguration; import org.springframework.boot.actuate.endpoint.convert.ConversionServiceParameterMapper; import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes; +import org.springframework.boot.actuate.endpoint.web.EndpointPathResolver; import org.springframework.boot.actuate.endpoint.web.annotation.WebAnnotationEndpointDiscoverer; import org.springframework.boot.endpoint.web.EndpointMapping; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; @@ -219,7 +220,7 @@ public class CloudFoundryMvcWebEndpointIntegrationTests { DefaultConversionService.getSharedInstance()); return new WebAnnotationEndpointDiscoverer(applicationContext, parameterMapper, (id) -> new CachingConfiguration(0), - endpointMediaTypes, (id) -> id); + endpointMediaTypes, EndpointPathResolver.useEndpointId()); } @Bean diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java index dfee5507b1..645fab0d90 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsAutoConfigurationTests.java @@ -47,7 +47,8 @@ public class MetricsAutoConfigurationTests { @Test public void autoConfiguredDataSourceIsInstrumented() { this.contextRunner - .withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class)) + .withConfiguration( + AutoConfigurations.of(DataSourceAutoConfiguration.class)) .withPropertyValues("spring.datasource.generate-unique-name=true", "spring.metrics.use-global-registry=false") .run((context) -> { @@ -61,7 +62,8 @@ public class MetricsAutoConfigurationTests { @Test public void autoConfiguredDataSourceWithCustomMetricName() { this.contextRunner - .withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class)) + .withConfiguration( + AutoConfigurations.of(DataSourceAutoConfiguration.class)) .withPropertyValues("spring.datasource.generate-unique-name=true", "spring.metrics.jdbc.datasource-metric-name=custom.name", "spring.metrics.use-global-registry=false") @@ -76,7 +78,8 @@ public class MetricsAutoConfigurationTests { @Test public void dataSourceInstrumentationCanBeDisabled() { this.contextRunner - .withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class)) + .withConfiguration( + AutoConfigurations.of(DataSourceAutoConfiguration.class)) .withPropertyValues("spring.datasource.generate-unique-name=true", "spring.metrics.jdbc.instrument-datasource=false", "spring.metrics.use-global-registry=false") @@ -90,15 +93,15 @@ public class MetricsAutoConfigurationTests { @Test public void allDataSourcesCanBeInstrumented() { - this.contextRunner - .withUserConfiguration(TwoDataSourcesConfiguration.class) - .withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class)) + this.contextRunner.withUserConfiguration(TwoDataSourcesConfiguration.class) + .withConfiguration( + AutoConfigurations.of(DataSourceAutoConfiguration.class)) .withPropertyValues("metrics.use-global-registry=false") .run((context) -> { - context.getBean("firstDataSource", DataSource.class) - .getConnection().getMetaData(); - context.getBean("secondOne", DataSource.class) - .getConnection().getMetaData(); + context.getBean("firstDataSource", DataSource.class).getConnection() + .getMetaData(); + context.getBean("secondOne", DataSource.class).getConnection() + .getMetaData(); MeterRegistry registry = context.getBean(MeterRegistry.class); assertThat(registry.find("data.source.max.connections") .tags("name", "first").meter()).isPresent(); diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ParameterMappingException.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ParameterMappingException.java index 90254b7165..f3dc19e104 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ParameterMappingException.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ParameterMappingException.java @@ -18,8 +18,7 @@ package org.springframework.boot.actuate.endpoint; /** * A {@code ParameterMappingException} is thrown when a failure occurs during - * {@link ParameterMapper#mapParameter(Object, Class) operation parameter - * mapping}. + * {@link ParameterMapper#mapParameter(Object, Class) operation parameter mapping}. * * @author Andy Wilkinson * @since 2.0.0 diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/convert/ConversionServiceParameterMapper.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/convert/ConversionServiceParameterMapper.java index 90095c8e90..437225af91 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/convert/ConversionServiceParameterMapper.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/convert/ConversionServiceParameterMapper.java @@ -23,15 +23,14 @@ import org.springframework.core.convert.ConversionService; import org.springframework.format.support.DefaultFormattingConversionService; /** - * {@link ParameterMapper} that uses a {@link ConversionService} to map parameter - * values if necessary. + * {@link ParameterMapper} that uses a {@link ConversionService} to map parameter values + * if necessary. * * @author Stephane Nicoll * @author Phillip Webb * @since 2.0.0 */ -public class ConversionServiceParameterMapper - implements ParameterMapper { +public class ConversionServiceParameterMapper implements ParameterMapper { private final ConversionService conversionService; @@ -43,8 +42,7 @@ public class ConversionServiceParameterMapper * Create a new instance with the {@link ConversionService} to use. * @param conversionService the conversion service */ - public ConversionServiceParameterMapper( - ConversionService conversionService) { + public ConversionServiceParameterMapper(ConversionService conversionService) { this.conversionService = new BinderConversionService(conversionService); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/annotation/JmxAnnotationEndpointDiscoverer.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/annotation/JmxAnnotationEndpointDiscoverer.java index 0c29409f1c..abeea74946 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/annotation/JmxAnnotationEndpointDiscoverer.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/annotation/JmxAnnotationEndpointDiscoverer.java @@ -115,8 +115,8 @@ public class JmxAnnotationEndpointDiscoverer public JmxEndpointOperation createOperation(String endpointId, AnnotationAttributes operationAttributes, Object target, Method method, OperationType type, long timeToLive) { - ReflectiveOperationInvoker invoker = new ReflectiveOperationInvoker( - target, method, this.parameterMapper); + ReflectiveOperationInvoker invoker = new ReflectiveOperationInvoker(target, + method, this.parameterMapper); String operationName = method.getName(); Class outputType = getJmxType(method.getReturnType()); String description = getDescription(method, diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/EndpointPathResolver.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/EndpointPathResolver.java index 073ef44795..171d146883 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/EndpointPathResolver.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/EndpointPathResolver.java @@ -32,4 +32,12 @@ public interface EndpointPathResolver { */ String resolvePath(String endpointId); + /** + * Returns an {@link EndpointPathResolver} that uses the endpoint ID as the path. + * @return an {@link EndpointPathResolver} that uses the endpoint ID as the path + */ + static EndpointPathResolver useEndpointId() { + return (endpointId) -> endpointId; + } + } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/WebAnnotationEndpointDiscoverer.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/WebAnnotationEndpointDiscoverer.java index 0e239c6e16..773140a77b 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/WebAnnotationEndpointDiscoverer.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/WebAnnotationEndpointDiscoverer.java @@ -30,8 +30,8 @@ import org.reactivestreams.Publisher; import org.springframework.boot.actuate.endpoint.EndpointExposure; import org.springframework.boot.actuate.endpoint.EndpointInfo; import org.springframework.boot.actuate.endpoint.OperationInvoker; -import org.springframework.boot.actuate.endpoint.ParameterMapper; import org.springframework.boot.actuate.endpoint.OperationType; +import org.springframework.boot.actuate.endpoint.ParameterMapper; import org.springframework.boot.actuate.endpoint.ReflectiveOperationInvoker; import org.springframework.boot.actuate.endpoint.annotation.AnnotationEndpointDiscoverer; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; @@ -67,8 +67,8 @@ public class WebAnnotationEndpointDiscoverer extends * {@link Endpoint endpoints} and {@link WebEndpointExtension web extensions} using * the given {@link ApplicationContext}. * @param applicationContext the application context - * @param parameterMapper the {@link ParameterMapper} used to - * convert arguments when an operation is invoked + * @param parameterMapper the {@link ParameterMapper} used to convert arguments when + * an operation is invoked * @param cachingConfigurationFactory the {@link CachingConfiguration} factory to use * @param endpointMediaTypes the media types produced and consumed by web endpoint * operations @@ -81,8 +81,8 @@ public class WebAnnotationEndpointDiscoverer extends EndpointMediaTypes endpointMediaTypes, EndpointPathResolver endpointPathResolver) { super(applicationContext, - new WebEndpointOperationFactory(parameterMapper, - endpointMediaTypes, endpointPathResolver), + new WebEndpointOperationFactory(parameterMapper, endpointMediaTypes, + endpointPathResolver), WebEndpointOperation::getRequestPredicate, cachingConfigurationFactory); } @@ -145,8 +145,8 @@ public class WebAnnotationEndpointDiscoverer extends determineConsumedMediaTypes(httpMethod, method), determineProducedMediaTypes( operationAttributes.getStringArray("produces"), method)); - OperationInvoker invoker = new ReflectiveOperationInvoker( - target, method, this.parameterMapper); + OperationInvoker invoker = new ReflectiveOperationInvoker(target, method, + this.parameterMapper); if (timeToLive > 0) { invoker = new CachingOperationInvoker(invoker, timeToLive); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractReactiveHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractReactiveHealthIndicator.java index 14ba42c9f4..f6550fc341 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractReactiveHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/AbstractReactiveHealthIndicator.java @@ -31,8 +31,7 @@ public abstract class AbstractReactiveHealthIndicator implements ReactiveHealthI @Override public final Mono health() { try { - return doHealthCheck(new Health.Builder()) - .onErrorResume(this::handleFailure); + return doHealthCheck(new Health.Builder()).onErrorResume(this::handleFailure); } catch (Exception ex) { return handleFailure(ex); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/AbstractWebEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/AbstractWebEndpointIntegrationTests.java index 82d5557744..743195033f 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/AbstractWebEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/AbstractWebEndpointIntegrationTests.java @@ -385,7 +385,7 @@ public abstract class AbstractWebEndpointIntegrationTests new CachingConfiguration(0), - endpointMediaTypes(), (id) -> id); + endpointMediaTypes(), EndpointPathResolver.useEndpointId()); } @Bean diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/WebAnnotationEndpointDiscovererTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/WebAnnotationEndpointDiscovererTests.java index 5f600eeac5..d455d3bcd2 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/WebAnnotationEndpointDiscovererTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/WebAnnotationEndpointDiscovererTests.java @@ -240,17 +240,18 @@ public class WebAnnotationEndpointDiscovererTests { @Test public void endpointPathCanBeCustomized() { load((id) -> null, (id) -> "custom/" + id, - AdditionalOperationWebEndpointConfiguration.class, (discoverer) -> { - Map> endpoints = mapEndpoints( - discoverer.discoverEndpoints()); - assertThat(endpoints).containsOnlyKeys("test"); - EndpointInfo endpoint = endpoints.get("test"); - assertThat(requestPredicates(endpoint)).has(requestPredicates( - path("custom/test").httpMethod(WebEndpointHttpMethod.GET).consumes() - .produces("application/json"), - path("custom/test/{id}").httpMethod(WebEndpointHttpMethod.GET).consumes() - .produces("application/json"))); - }); + AdditionalOperationWebEndpointConfiguration.class, (discoverer) -> { + Map> endpoints = mapEndpoints( + discoverer.discoverEndpoints()); + assertThat(endpoints).containsOnlyKeys("test"); + EndpointInfo endpoint = endpoints.get("test"); + Condition> expected = requestPredicates( + path("custom/test").httpMethod(WebEndpointHttpMethod.GET) + .consumes().produces("application/json"), + path("custom/test/{id}").httpMethod(WebEndpointHttpMethod.GET) + .consumes().produces("application/json")); + assertThat(requestPredicates(endpoint)).has(expected); + }); } private void load(Class configuration, @@ -259,20 +260,18 @@ public class WebAnnotationEndpointDiscovererTests { } private void load(CachingConfigurationFactory cachingConfigurationFactory, - EndpointPathResolver endpointPathResolver, - Class configuration, Consumer consumer) { + EndpointPathResolver endpointPathResolver, Class configuration, + Consumer consumer) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( configuration); try { - consumer.accept( - new WebAnnotationEndpointDiscoverer(context, - new ConversionServiceParameterMapper( - DefaultConversionService.getSharedInstance()), - cachingConfigurationFactory, - new EndpointMediaTypes( - Collections.singletonList("application/json"), - Collections.singletonList("application/json")), - endpointPathResolver)); + consumer.accept(new WebAnnotationEndpointDiscoverer(context, + new ConversionServiceParameterMapper( + DefaultConversionService.getSharedInstance()), + cachingConfigurationFactory, + new EndpointMediaTypes(Collections.singletonList("application/json"), + Collections.singletonList("application/json")), + endpointPathResolver)); } finally { context.close(); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/JerseyEndpointsRunner.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/JerseyEndpointsRunner.java index 172f0d7c6c..4bf8c8ebde 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/JerseyEndpointsRunner.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/JerseyEndpointsRunner.java @@ -31,6 +31,7 @@ import org.junit.runners.model.InitializationError; import org.springframework.boot.actuate.endpoint.convert.ConversionServiceParameterMapper; import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType; import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes; +import org.springframework.boot.actuate.endpoint.web.EndpointPathResolver; import org.springframework.boot.actuate.endpoint.web.annotation.WebAnnotationEndpointDiscoverer; import org.springframework.boot.actuate.endpoint.web.jersey.JerseyEndpointResourceFactory; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -97,9 +98,9 @@ class JerseyEndpointsRunner extends AbstractWebEndpointRunner { EndpointMediaTypes endpointMediaTypes = new EndpointMediaTypes(mediaTypes, mediaTypes); WebAnnotationEndpointDiscoverer discoverer = new WebAnnotationEndpointDiscoverer( - this.applicationContext, - new ConversionServiceParameterMapper(), (id) -> null, - endpointMediaTypes, (id) -> id); + this.applicationContext, new ConversionServiceParameterMapper(), + (id) -> null, endpointMediaTypes, + EndpointPathResolver.useEndpointId()); Collection resources = new JerseyEndpointResourceFactory() .createEndpointResources(new EndpointMapping("/application"), discoverer.discoverEndpoints(), endpointMediaTypes); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebFluxEndpointsRunner.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebFluxEndpointsRunner.java index bd23237d50..b24bbda68e 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebFluxEndpointsRunner.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebFluxEndpointsRunner.java @@ -25,6 +25,7 @@ import org.junit.runners.model.InitializationError; import org.springframework.boot.actuate.endpoint.convert.ConversionServiceParameterMapper; import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType; import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes; +import org.springframework.boot.actuate.endpoint.web.EndpointPathResolver; import org.springframework.boot.actuate.endpoint.web.annotation.WebAnnotationEndpointDiscoverer; import org.springframework.boot.actuate.endpoint.web.reactive.WebFluxEndpointHandlerMapping; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -103,9 +104,9 @@ class WebFluxEndpointsRunner extends AbstractWebEndpointRunner { EndpointMediaTypes endpointMediaTypes = new EndpointMediaTypes(mediaTypes, mediaTypes); WebAnnotationEndpointDiscoverer discoverer = new WebAnnotationEndpointDiscoverer( - this.applicationContext, - new ConversionServiceParameterMapper(), (id) -> null, - endpointMediaTypes, (id) -> id); + this.applicationContext, new ConversionServiceParameterMapper(), + (id) -> null, endpointMediaTypes, + EndpointPathResolver.useEndpointId()); return new WebFluxEndpointHandlerMapping(new EndpointMapping("/application"), discoverer.discoverEndpoints(), endpointMediaTypes, new CorsConfiguration()); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebMvcEndpointRunner.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebMvcEndpointRunner.java index 1070934aa1..422828e150 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebMvcEndpointRunner.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebMvcEndpointRunner.java @@ -25,6 +25,7 @@ import org.junit.runners.model.InitializationError; import org.springframework.boot.actuate.endpoint.convert.ConversionServiceParameterMapper; import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType; import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes; +import org.springframework.boot.actuate.endpoint.web.EndpointPathResolver; import org.springframework.boot.actuate.endpoint.web.annotation.WebAnnotationEndpointDiscoverer; import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -86,9 +87,9 @@ class WebMvcEndpointRunner extends AbstractWebEndpointRunner { EndpointMediaTypes endpointMediaTypes = new EndpointMediaTypes(mediaTypes, mediaTypes); WebAnnotationEndpointDiscoverer discoverer = new WebAnnotationEndpointDiscoverer( - this.applicationContext, - new ConversionServiceParameterMapper(), (id) -> null, - endpointMediaTypes, (id) -> id); + this.applicationContext, new ConversionServiceParameterMapper(), + (id) -> null, endpointMediaTypes, + EndpointPathResolver.useEndpointId()); return new WebMvcEndpointHandlerMapping(new EndpointMapping("/application"), discoverer.discoverEndpoints(), endpointMediaTypes, new CorsConfiguration()); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java index 7e863b4f23..c0d73e1b9b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java @@ -80,7 +80,8 @@ public class BatchAutoConfiguration { @ConditionalOnBean(DataSource.class) public BatchDataSourceInitializer batchDataSourceInitializer(DataSource dataSource, ResourceLoader resourceLoader) { - return new BatchDataSourceInitializer(dataSource, resourceLoader, this.properties); + return new BatchDataSourceInitializer(dataSource, resourceLoader, + this.properties); } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherCommandLineRunner.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherCommandLineRunner.java index 45363da15a..63f67f3c9e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherCommandLineRunner.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherCommandLineRunner.java @@ -141,8 +141,8 @@ public class JobLauncherCommandLineRunner throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException, JobParametersNotFoundException { - JobParameters nextParameters = new JobParametersBuilder(jobParameters, this.jobExplorer) - .getNextJobParameters(job).toJobParameters(); + JobParameters nextParameters = new JobParametersBuilder(jobParameters, + this.jobExplorer).getNextJobParameters(job).toJobParameters(); JobExecution execution = this.jobLauncher.run(job, nextParameters); if (this.publisher != null) { this.publisher.publishEvent(new JobExecutionEvent(execution)); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java index 19357dc3b8..10b1db16c4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java @@ -129,8 +129,7 @@ class DataSourceInitializer { if (mode == DataSourceInitializationMode.NEVER) { return false; } - if (mode == DataSourceInitializationMode.EMBEDDED - && !isEmbedded()) { + if (mode == DataSourceInitializationMode.EMBEDDED && !isEmbedded()) { return false; } return true; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java index b3b630980c..ffce11db66 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java @@ -153,7 +153,8 @@ public class QuartzAutoConfiguration { public QuartzDataSourceInitializer quartzDataSourceInitializer( DataSource dataSource, ResourceLoader resourceLoader, QuartzProperties properties) { - return new QuartzDataSourceInitializer(dataSource, resourceLoader, properties); + return new QuartzDataSourceInitializer(dataSource, resourceLoader, + properties); } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializer.java index 8d7388ceaf..3a7f7f1212 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzDataSourceInitializer.java @@ -33,8 +33,8 @@ public class QuartzDataSourceInitializer extends AbstractDataSourceInitializer { private final QuartzProperties properties; - public QuartzDataSourceInitializer(DataSource dataSource, ResourceLoader resourceLoader, - QuartzProperties properties) { + public QuartzDataSourceInitializer(DataSource dataSource, + ResourceLoader resourceLoader, QuartzProperties properties) { super(dataSource, resourceLoader); Assert.notNull(properties, "QuartzProperties must not be null"); this.properties = properties; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfiguration.java index bdb0073c71..5b84a5c52f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfiguration.java @@ -40,7 +40,8 @@ class OAuth2WebSecurityConfiguration { @Bean @ConditionalOnMissingBean - public OAuth2AuthorizedClientService authorizedClientService(ClientRegistrationRepository clientRegistrationRepository) { + public OAuth2AuthorizedClientService authorizedClientService( + ClientRegistrationRepository clientRegistrationRepository) { return new InMemoryOAuth2AuthorizedClientService(clientRegistrationRepository); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveAuthenticationManagerConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveAuthenticationManagerConfiguration.java index 95f886075b..76f50182bf 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveAuthenticationManagerConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveAuthenticationManagerConfiguration.java @@ -58,12 +58,16 @@ class ReactiveAuthenticationManagerConfiguration { ObjectProvider passwordEncoder) { String password = UUID.randomUUID().toString(); logger.info(String.format("%n%nUsing default security password: %s%n", password)); + UserDetails userDetails = getUserDetails(password, passwordEncoder); + return new MapReactiveUserDetailsService(userDetails); + } + + private UserDetails getUserDetails(String password, + ObjectProvider passwordEncoder) { String encodedPassword = passwordEncoder .getIfAvailable(PasswordEncoderFactories::createDelegatingPasswordEncoder) .encode(password); - UserDetails user = User.withUsername("user").password(encodedPassword).roles() - .build(); - return new MapReactiveUserDetailsService(user); + return User.withUsername("user").password(encodedPassword).roles().build(); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionConfiguration.java index 2cf29c0d75..e71503d722 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/JdbcSessionConfiguration.java @@ -52,7 +52,8 @@ class JdbcSessionConfiguration { public JdbcSessionDataSourceInitializer jdbcSessionDataSourceInitializer( DataSource dataSource, ResourceLoader resourceLoader, JdbcSessionProperties properties) { - return new JdbcSessionDataSourceInitializer(dataSource, resourceLoader, properties); + return new JdbcSessionDataSourceInitializer(dataSource, resourceLoader, + properties); } @Configuration diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java index 4485ebfed7..628868f52a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java @@ -155,6 +155,7 @@ public abstract class AbstractErrorWebExceptionHandler } } catch (Exception ex) { + // Ignore } } return null; @@ -205,30 +206,34 @@ public abstract class AbstractErrorWebExceptionHandler @Override public Mono handle(ServerWebExchange exchange, Throwable throwable) { - this.errorAttributes.storeErrorInformation(throwable, exchange); ServerRequest request = ServerRequest.create(exchange, this.messageReaders); return getRoutingFunction(this.errorAttributes).route(request) .switchIfEmpty(Mono.error(throwable)) - .flatMap((handler) -> handler.handle(request)).flatMap((response) -> { - // force content-type since writeTo won't overwrite response header - // values - exchange.getResponse().getHeaders() - .setContentType(response.headers().getContentType()); - return response.writeTo(exchange, new ServerResponse.Context() { + .flatMap((handler) -> handler.handle(request)) + .flatMap((response) -> write(exchange, response)); + } - @Override - public List> messageWriters() { - return AbstractErrorWebExceptionHandler.this.messageWriters; - } + private Mono write(ServerWebExchange exchange, + ServerResponse response) { + // force content-type since writeTo won't overwrite response header values + exchange.getResponse().getHeaders() + .setContentType(response.headers().getContentType()); + return response.writeTo(exchange, new ResponseContext()); + } - @Override - public List viewResolvers() { - return AbstractErrorWebExceptionHandler.this.viewResolvers; - } + private class ResponseContext implements ServerResponse.Context { + + @Override + public List> messageWriters() { + return AbstractErrorWebExceptionHandler.this.messageWriters; + } + + @Override + public List viewResolvers() { + return AbstractErrorWebExceptionHandler.this.viewResolvers; + } - }); - }); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorAttributes.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorAttributes.java index 34ef5d520a..b4852a78d6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorAttributes.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorAttributes.java @@ -124,7 +124,6 @@ public class DefaultErrorAttributes implements ErrorAttributes { @Override public void storeErrorInformation(Throwable error, ServerWebExchange exchange) { exchange.getAttributes().putIfAbsent(ERROR_ATTRIBUTE, error); - } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java index e6799a90a5..aae55ad09c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java @@ -40,12 +40,10 @@ import org.springframework.web.reactive.function.server.ServerResponse; /** * Basic global {@link org.springframework.web.server.WebExceptionHandler}, rendering * {@link ErrorAttributes}. - * *

* More specific errors can be handled either using Spring WebFlux abstractions (e.g. * {@code @ExceptionHandler} with the annotation model) or by adding * {@link RouterFunction} to the chain. - * *

* This implementation will render error as HTML views if the client explicitly supports * that media type. It attempts to resolve error views using well known conventions. Will @@ -61,10 +59,8 @@ import org.springframework.web.reactive.function.server.ServerResponse; *

  • {@code '//error/error'}
  • *
  • {@code '//error/error.html'}
  • * - * *

    * If none found, a default "Whitelabel Error" HTML view will be rendered. - * *

    * If the client doesn't support HTML, the error information will be rendered as a JSON * payload. @@ -87,7 +83,6 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa /** * Create a new {@code DefaultErrorWebExceptionHandler} instance. - * * @param errorAttributes the error attributes * @param resourceProperties the resources configuration properties * @param errorProperties the error configuration properties @@ -103,7 +98,6 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa @Override protected RouterFunction getRoutingFunction( ErrorAttributes errorAttributes) { - return RouterFunctions.route(acceptsTextHtml(), this::renderErrorView) .andRoute(RequestPredicates.all(), this::renderErrorResponse); } @@ -116,11 +110,9 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa protected Mono renderErrorView(ServerRequest request) { boolean includeStackTrace = isIncludeStackTrace(request, MediaType.TEXT_HTML); Map error = getErrorAttributes(request, includeStackTrace); - HttpStatus errorStatus = getHttpStatus(error); ServerResponse.BodyBuilder response = ServerResponse.status(errorStatus) .contentType(MediaType.TEXT_HTML); - return Flux .just("error/" + errorStatus.toString(), "error/" + SERIES_VIEWS.get(errorStatus.series()), "error/error") diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/MixedNeo4jRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/MixedNeo4jRepositoriesAutoConfigurationTests.java index 3548e76db6..51a4af4953 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/MixedNeo4jRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/neo4j/MixedNeo4jRepositoriesAutoConfigurationTests.java @@ -94,8 +94,7 @@ public class MixedNeo4jRepositoriesAutoConfigurationTests { private void load(Class config, String... environment) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); TestPropertyValues.of(environment) - .and("spring.datasource.initialization-mode=never") - .applyTo(context); + .and("spring.datasource.initialization-mode=never").applyTo(context); context.register(config); context.register(DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java index dbf67c2f8d..c00a23d1b0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerInvokerTests.java @@ -111,8 +111,7 @@ public class DataSourceInitializerInvokerTests { @Test public void dataSourceInitializedWithMultipleScripts() { this.contextRunner - .withPropertyValues( - "spring.datasource.initialization-mode:always", + .withPropertyValues("spring.datasource.initialization-mode:always", "spring.datasource.schema:" + getRelativeLocationFor("schema.sql") + "," + getRelativeLocationFor("another.sql"), "spring.datasource.data:" + getRelativeLocationFor("data.sql")) @@ -130,12 +129,13 @@ public class DataSourceInitializerInvokerTests { @Test public void dataSourceInitializedWithExplicitSqlScriptEncoding() { - this.contextRunner.withPropertyValues( - "spring.datasource.initialization-mode:always", - "spring.datasource.sqlScriptEncoding:UTF-8", - "spring.datasource.schema:" - + getRelativeLocationFor("encoding-schema.sql"), - "spring.datasource.data:" + getRelativeLocationFor("encoding-data.sql")) + this.contextRunner + .withPropertyValues("spring.datasource.initialization-mode:always", + "spring.datasource.sqlScriptEncoding:UTF-8", + "spring.datasource.schema:" + + getRelativeLocationFor("encoding-schema.sql"), + "spring.datasource.data:" + + getRelativeLocationFor("encoding-data.sql")) .run((context) -> { DataSource dataSource = context.getBean(DataSource.class); assertThat(dataSource).isInstanceOf(HikariDataSource.class); @@ -266,8 +266,7 @@ public class DataSourceInitializerInvokerTests { @Test public void dataSourceInitializedWithInvalidDataResource() { this.contextRunner - .withPropertyValues( - "spring.datasource.initialization-mode:always", + .withPropertyValues("spring.datasource.initialization-mode:always", "spring.datasource.schema:" + getRelativeLocationFor("schema.sql"), "spring.datasource.data:classpath:does/not/exist.sql") diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerTests.java index cd413004c2..f89526d7ff 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializerTests.java @@ -94,7 +94,6 @@ public class DataSourceInitializerTests { given(connection.getMetaData()).willReturn(metadata); DataSource dataSource = mock(DataSource.class); given(dataSource.getConnection()).willReturn(connection); - DataSourceInitializer initializer = new DataSourceInitializer(dataSource, new DataSourceProperties()); assertThat(initializer.createSchema()).isFalse(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java index 09c69d4453..ffb11a8449 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourcePropertiesTests.java @@ -68,8 +68,8 @@ public class DataSourcePropertiesTests { @Test public void determineUrlWithNoEmbeddedSupport() throws Exception { DataSourceProperties properties = new DataSourceProperties(); - properties.setBeanClassLoader(new HidePackagesClassLoader("org.h2", - "org.apache.derby", "org.hsqldb")); + properties.setBeanClassLoader( + new HidePackagesClassLoader("org.h2", "org.apache.derby", "org.hsqldb")); properties.afterPropertiesSet(); this.thrown.expect(DataSourceProperties.DataSourceBeanCreationException.class); this.thrown.expectMessage("Cannot determine embedded database url"); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfigurationTests.java index d2df13de6f..1fa370241d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfigurationTests.java @@ -121,14 +121,12 @@ public class JndiDataSourceAutoConfigurationTests { throws IllegalStateException, NamingException { DataSource dataSource = new BasicDataSource(); configureJndi("foo", dataSource); - this.context = new AnnotationConfigApplicationContext(); TestPropertyValues.of("spring.datasource.jndi-name:foo").applyTo(this.context); this.context.register(JndiDataSourceAutoConfiguration.class, MBeanExporterConfiguration.class, AnotherMBeanExporterConfiguration.class); this.context.refresh(); - assertThat(this.context.getBean(DataSource.class)).isEqualTo(dataSource); for (MBeanExporter exporter : this.context.getBeansOfType(MBeanExporter.class) .values()) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java index a58d02ce17..64d0f12b64 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java @@ -328,15 +328,14 @@ public class KafkaAutoConfigurationTests { @Test public void testConcurrentKafkaListenerContainerFactoryWithKafkaTemplate() { - this.contextRunner - .run((context) -> { - ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory = context - .getBean(ConcurrentKafkaListenerContainerFactory.class); - DirectFieldAccessor dfa = new DirectFieldAccessor( - kafkaListenerContainerFactory); - assertThat(dfa.getPropertyValue("replyTemplate")) - .isSameAs(context.getBean(KafkaTemplate.class)); - }); + this.contextRunner.run((context) -> { + ConcurrentKafkaListenerContainerFactory kafkaListenerContainerFactory = context + .getBean(ConcurrentKafkaListenerContainerFactory.class); + DirectFieldAccessor dfa = new DirectFieldAccessor( + kafkaListenerContainerFactory); + assertThat(dfa.getPropertyValue("replyTemplate")) + .isSameAs(context.getBean(KafkaTemplate.class)); + }); } @Configuration diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java index b06f4709c5..1a67813be3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java @@ -208,8 +208,10 @@ public class SecurityAutoConfigurationTests { public void testJpaCoexistsHappily() throws Exception { this.context = new AnnotationConfigWebApplicationContext(); this.context.setServletContext(new MockServletContext()); - TestPropertyValues.of("spring.datasource.url:jdbc:hsqldb:mem:testsecdb", - "spring.datasource.initialization-mode:never").applyTo(this.context); + TestPropertyValues + .of("spring.datasource.url:jdbc:hsqldb:mem:testsecdb", + "spring.datasource.initialization-mode:never") + .applyTo(this.context); this.context.register(EntityConfiguration.class, PropertyPlaceholderAutoConfiguration.class, DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfigurationTests.java index 9d240b4a33..b7c4a5f202 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2WebSecurityConfigurationTests.java @@ -92,11 +92,10 @@ public class OAuth2WebSecurityConfigurationTests { @Test public void configurationRegistersAuthorizedClientServiceBean() throws Exception { - this.contextRunner - .withUserConfiguration(ClientRepositoryConfiguration.class, - OAuth2WebSecurityConfiguration.class) - .run(context -> { - OAuth2AuthorizedClientService bean = context.getBean(OAuth2AuthorizedClientService.class); + this.contextRunner.withUserConfiguration(ClientRepositoryConfiguration.class, + OAuth2WebSecurityConfiguration.class).run(context -> { + OAuth2AuthorizedClientService bean = context + .getBean(OAuth2AuthorizedClientService.class); OAuth2AuthorizedClientService authorizedClientService = (OAuth2AuthorizedClientService) ReflectionTestUtils .getField(getAuthCodeFilters(context).get(0), "authorizedClientService"); @@ -110,7 +109,8 @@ public class OAuth2WebSecurityConfigurationTests { .withUserConfiguration(OAuth2AuthorizedClientServiceConfiguration.class, OAuth2WebSecurityConfiguration.class) .run(context -> { - OAuth2AuthorizedClientService bean = context.getBean(OAuth2AuthorizedClientService.class); + OAuth2AuthorizedClientService bean = context + .getBean(OAuth2AuthorizedClientService.class); OAuth2AuthorizedClientService authorizedClientService = (OAuth2AuthorizedClientService) ReflectionTestUtils .getField(getAuthCodeFilters(context).get(0), "authorizedClientService"); @@ -211,8 +211,10 @@ public class OAuth2WebSecurityConfigurationTests { static class OAuth2AuthorizedClientServiceConfiguration { @Bean - public OAuth2AuthorizedClientService testAuthorizedClientService(ClientRegistrationRepository clientRegistrationRepository) { - return new InMemoryOAuth2AuthorizedClientService(clientRegistrationRepository); + public OAuth2AuthorizedClientService testAuthorizedClientService( + ClientRegistrationRepository clientRegistrationRepository) { + return new InMemoryOAuth2AuthorizedClientService( + clientRegistrationRepository); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveSecurityAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveSecurityAutoConfigurationTests.java index a3e71e11d0..e6bf1278f9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveSecurityAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveSecurityAutoConfigurationTests.java @@ -56,8 +56,7 @@ public class ReactiveSecurityAutoConfigurationTests { .withConfiguration( AutoConfigurations.of(ReactiveSecurityAutoConfiguration.class)) .run((context) -> { - assertThat(context).getBean(WebFilterChainProxy.class) - .isNotNull(); + assertThat(context).getBean(WebFilterChainProxy.class).isNotNull(); assertThat(context).getBean(WebFluxSecurityConfiguration.class) .isNotNull(); assertThat(context).getBean(WebFilterChainProxy.class).isNotNull(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorAttributesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorAttributesTests.java index 61869c6326..2439a6aed8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorAttributesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorAttributesTests.java @@ -159,11 +159,9 @@ public class DefaultErrorAttributesTests { Collections.singletonMap("a", "b"), "objectName"); bindingResult.addError(new ObjectError("c", "d")); Exception ex = new WebExchangeBindException(stringParam, bindingResult); - MockServerHttpRequest request = MockServerHttpRequest.get("/test").build(); Map attributes = this.errorAttributes .getErrorAttributes(buildServerRequest(request, ex), false); - assertThat(attributes.get("message")).asString() .startsWith("Validation failed for argument at index 0 in method: " + "public int org.springframework.boot.autoconfigure.web.reactive.error.DefaultErrorAttributesTests" diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebTestClientSpringBootTestIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebTestClientSpringBootTestIntegrationTests.java index 2733882ffd..39464877ef 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebTestClientSpringBootTestIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebTestClientSpringBootTestIntegrationTests.java @@ -71,12 +71,14 @@ public class WebTestClientSpringBootTestIntegrationTests { @Configuration static class TestConfiguration { + @Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) throws Exception { http.authorizeExchange().anyExchange().permitAll(); return http.build(); } + } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java index c4b47c3402..579f7ef16e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java @@ -708,8 +708,8 @@ public class ConfigurationMetadataAnnotationProcessorTests { private Metadata.MetadataItemCondition webPath(String endpointId) { return Metadata.withProperty("endpoints." + endpointId + ".web.path") - .ofType(String.class).withDefaultValue(endpointId).withDescription(String - .format("Path of the %s endpoint.", endpointId)); + .ofType(String.class).withDefaultValue(endpointId) + .withDescription(String.format("Path of the %s endpoint.", endpointId)); } private Metadata.MetadataItemCondition cacheTtl(String endpointId) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java index b2a516d06c..50ccb221aa 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java @@ -141,9 +141,8 @@ final class JavaPluginAction implements PluginApplicationAction { private void configureAdditionalMetadataLocations(Project project) { project.afterEvaluate((evaluated) -> { - evaluated.getTasks().withType(JavaCompile.class, (compile) -> { - configureAdditionalMetadataLocations(project, compile); - }); + evaluated.getTasks().withType(JavaCompile.class, + (compile) -> configureAdditionalMetadataLocations(project, compile)); }); } diff --git a/spring-boot-project/spring-boot/pom.xml b/spring-boot-project/spring-boot/pom.xml index beace20ba5..6a106b9e21 100644 --- a/spring-boot-project/spring-boot/pom.xml +++ b/spring-boot-project/spring-boot/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 org.springframework.boot diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java index 8cd9599735..8faab73a46 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessor.java @@ -118,20 +118,20 @@ public class ConfigurationPropertiesBindingPostProcessor + "PropertySourcesPlaceholderConfigurer or Environment"); } PropertySources appliedPropertySources = configurer.getAppliedPropertySources(); - return environmentPropertySources == null ? appliedPropertySources - : new CompositePropertySources( - new FilteredPropertySources(appliedPropertySources, - PropertySourcesPlaceholderConfigurer.ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME), - environmentPropertySources); + if (environmentPropertySources == null) { + return appliedPropertySources; + } + return new CompositePropertySources( + new FilteredPropertySources(appliedPropertySources, + PropertySourcesPlaceholderConfigurer.ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME), + environmentPropertySources); } private MutablePropertySources extractEnvironmentPropertySources() { - MutablePropertySources environmentPropertySources = null; if (this.environment instanceof ConfigurableEnvironment) { - environmentPropertySources = ((ConfigurableEnvironment) this.environment) - .getPropertySources(); + return ((ConfigurableEnvironment) this.environment).getPropertySources(); } - return environmentPropertySources; + return null; } private PropertySourcesPlaceholderConfigurer getSinglePropertySourcesPlaceholderConfigurer() { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/FilteredPropertySources.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/FilteredPropertySources.java index 33458683f4..b213f5cf21 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/FilteredPropertySources.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/FilteredPropertySources.java @@ -20,7 +20,6 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.StreamSupport; import org.springframework.core.env.PropertySource; @@ -33,21 +32,15 @@ import org.springframework.core.env.PropertySources; */ final class FilteredPropertySources implements PropertySources { - private final Set filtered; - private final PropertySources delegate; + private final Set filtered; + FilteredPropertySources(PropertySources delegate, String... filtered) { this.delegate = delegate; this.filtered = new HashSet<>(Arrays.asList(filtered)); } - @Override - public Iterator> iterator() { - return StreamSupport.stream(this.delegate.spliterator(), false) - .filter(this::included).collect(Collectors.toList()).iterator(); - } - @Override public boolean contains(String name) { if (included(name)) { @@ -64,6 +57,12 @@ final class FilteredPropertySources implements PropertySources { return null; } + @Override + public Iterator> iterator() { + return StreamSupport.stream(this.delegate.spliterator(), false) + .filter(this::included).iterator(); + } + private boolean included(PropertySource propertySource) { return included(propertySource.getName()); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactory.java index c51106b1d0..c08ee9e052 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactory.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.List; import reactor.ipc.netty.http.server.HttpServer; +import reactor.ipc.netty.http.server.HttpServerOptions.Builder; import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory; import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; @@ -66,33 +67,30 @@ public class NettyReactiveWebServerFactory extends AbstractReactiveWebServerFact } /** - * Set {@link NettyServerCustomizer}s that should be applied to the Netty - * server builder. Calling this method will replace any existing customizers. + * Set {@link NettyServerCustomizer}s that should be applied to the Netty server + * builder. Calling this method will replace any existing customizers. * @param nettyServerCustomizers the customizers to set */ public void setNettyServerCustomizers( Collection nettyServerCustomizers) { - Assert.notNull(nettyServerCustomizers, - "NettyServerCustomizers must not be null"); + Assert.notNull(nettyServerCustomizers, "NettyServerCustomizers must not be null"); this.nettyServerCustomizers = new ArrayList<>(nettyServerCustomizers); } - /** * Add {@link NettyServerCustomizer}s that should applied while building the server. * @param nettyServerCustomizer the customizers to add */ - public void addContextCustomizers( - NettyServerCustomizer... nettyServerCustomizer) { + public void addContextCustomizers(NettyServerCustomizer... nettyServerCustomizer) { Assert.notNull(nettyServerCustomizer, "NettyWebServerCustomizer must not be null"); this.nettyServerCustomizers.addAll(Arrays.asList(nettyServerCustomizer)); } private HttpServer createHttpServer() { - return HttpServer.builder().options(options -> { + return HttpServer.builder().options((options) -> { options.listenAddress(getListenAddress()); - this.nettyServerCustomizers.forEach(customizer -> customizer.customize(options)); + applyCustomizers(options); }).build(); } @@ -100,9 +98,12 @@ public class NettyReactiveWebServerFactory extends AbstractReactiveWebServerFact if (getAddress() != null) { return new InetSocketAddress(getAddress().getHostAddress(), getPort()); } - else { - return new InetSocketAddress(getPort()); - } + return new InetSocketAddress(getPort()); + } + + private void applyCustomizers(Builder options) { + this.nettyServerCustomizers + .forEach((customizer) -> customizer.customize(options)); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyServerCustomizer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyServerCustomizer.java index c13f170201..0817247c9f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyServerCustomizer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyServerCustomizer.java @@ -33,4 +33,5 @@ public interface NettyServerCustomizer { * @param builder the server options builder to customize */ void customize(HttpServerOptions.Builder builder); + } diff --git a/spring-boot-project/spring-boot/src/main/kotlin/org/springframework/boot/SpringApplicationExtensions.kt b/spring-boot-project/spring-boot/src/main/kotlin/org/springframework/boot/SpringApplicationExtensions.kt index e64c6a1e4b..8a304615e2 100644 --- a/spring-boot-project/spring-boot/src/main/kotlin/org/springframework/boot/SpringApplicationExtensions.kt +++ b/spring-boot-project/spring-boot/src/main/kotlin/org/springframework/boot/SpringApplicationExtensions.kt @@ -20,7 +20,6 @@ import org.springframework.context.ConfigurableApplicationContext import kotlin.reflect.KClass - /** * Top level function acting as a Kotlin shortcut allowing to write * `runApplication(arg1, arg2)` instead of diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactoryTests.java index 2eb54193e3..f0d3c4a249 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactoryTests.java @@ -66,7 +66,6 @@ public class NettyReactiveWebServerFactoryTests } factory.setNettyServerCustomizers(Arrays.asList(customizers[0], customizers[1])); this.webServer = factory.getWebServer(new EchoHandler()); - InOrder ordered = inOrder((Object[]) customizers); for (NettyServerCustomizer customizer : customizers) { ordered.verify(customizer).customize(any(HttpServerOptions.Builder.class)); diff --git a/spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/SpringApplicationExtensionsTests.kt b/spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/SpringApplicationExtensionsTests.kt index 963e0308f1..261700c43d 100644 --- a/spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/SpringApplicationExtensionsTests.kt +++ b/spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/SpringApplicationExtensionsTests.kt @@ -117,6 +117,7 @@ class SpringApplicationExtensionsTests { open fun webServer(): MockServletWebServerFactory { return MockServletWebServerFactory() } + } } diff --git a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/InsecureManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/InsecureManagementPortAndPathSampleActuatorApplicationTests.java index 0729ce4ad4..f3a8378e37 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/InsecureManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/InsecureManagementPortAndPathSampleActuatorApplicationTests.java @@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { - "management.server.port=0", "management.server.context-path=/management"}) + "management.server.port=0", "management.server.context-path=/management" }) @DirtiesContext public class InsecureManagementPortAndPathSampleActuatorApplicationTests { @@ -59,17 +59,17 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests { @Test public void testSecureActuator() throws Exception { - ResponseEntity entity = new TestRestTemplate().getForEntity( - "http://localhost:" + this.managementPort + "/management/application/health", - String.class); + ResponseEntity entity = new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + + "/management/application/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void testInsecureActuator() throws Exception { - ResponseEntity entity = new TestRestTemplate().getForEntity( - "http://localhost:" + this.managementPort + "/management/application/status", - String.class); + ResponseEntity entity = new TestRestTemplate() + .getForEntity("http://localhost:" + this.managementPort + + "/management/application/status", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); } @@ -77,9 +77,8 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests { @Test public void testMissing() throws Exception { ResponseEntity entity = new TestRestTemplate("admin", "admin") - .getForEntity( - "http://localhost:" + this.managementPort + "/management/application/missing", - String.class); + .getForEntity("http://localhost:" + this.managementPort + + "/management/application/missing", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); assertThat(entity.getBody()).contains("\"status\":404"); } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java index 3d9b52e112..60a065a3fc 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java @@ -62,8 +62,8 @@ public class ManagementAddressActuatorApplicationTests { @Test public void testHealth() throws Exception { ResponseEntity entity = new TestRestTemplate() - .withBasicAuth("user", getPassword()) - .getForEntity("http://localhost:" + this.managementPort + "/admin/application/health", + .withBasicAuth("user", getPassword()).getForEntity("http://localhost:" + + this.managementPort + "/admin/application/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java index c4ccff1ffb..f9cac23d5b 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java @@ -49,9 +49,9 @@ public class ServletPathSampleActuatorApplicationTests { @Test public void testErrorPath() throws Exception { @SuppressWarnings("rawtypes") - ResponseEntity entity = this.restTemplate.withBasicAuth("user", getPassword()) - .getForEntity("/spring/error", - Map.class); + ResponseEntity entity = this.restTemplate + .withBasicAuth("user", getPassword()) + .getForEntity("/spring/error", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); @SuppressWarnings("unchecked") Map body = entity.getBody(); diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/City.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/City.java index b0c6f25b90..ea41afba99 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/City.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/City.java @@ -30,7 +30,7 @@ public class City implements Serializable { private static final long serialVersionUID = 1L; @Id - @SequenceGenerator(name="city_generator", sequenceName="city_sequence", initialValue = 23) + @SequenceGenerator(name = "city_generator", sequenceName = "city_sequence", initialValue = 23) @GeneratedValue(generator = "city_generator") private Long id; diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Hotel.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Hotel.java index 3483b0471e..35764736fa 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Hotel.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Hotel.java @@ -36,7 +36,7 @@ public class Hotel implements Serializable { private static final long serialVersionUID = 1L; @Id - @SequenceGenerator(name="hotel_generator", sequenceName="hotel_sequence", initialValue = 28) + @SequenceGenerator(name = "hotel_generator", sequenceName = "hotel_sequence", initialValue = 28) @GeneratedValue(generator = "hotel_generator") private Long id; diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Review.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Review.java index 58cded2849..761f3557c1 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Review.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/domain/Review.java @@ -38,7 +38,7 @@ public class Review implements Serializable { private static final long serialVersionUID = 1L; @Id - @SequenceGenerator(name="review_generator", sequenceName="review_sequence", initialValue = 64) + @SequenceGenerator(name = "review_generator", sequenceName = "review_sequence", initialValue = 64) @GeneratedValue(generator = "review_generator") private Long id; diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/City.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/City.java index a0a6292034..2f4f6a2e19 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/City.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/City.java @@ -30,7 +30,7 @@ public class City implements Serializable { private static final long serialVersionUID = 1L; @Id - @SequenceGenerator(name="city_generator", sequenceName="city_sequence", initialValue = 23) + @SequenceGenerator(name = "city_generator", sequenceName = "city_sequence", initialValue = 23) @GeneratedValue(generator = "city_generator") private Long id; diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/Hotel.java b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/Hotel.java index 52a5cbd65a..4be17b2f26 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/Hotel.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/main/java/sample/data/rest/domain/Hotel.java @@ -33,7 +33,7 @@ public class Hotel implements Serializable { private static final long serialVersionUID = 1L; @Id - @SequenceGenerator(name="hotel_generator", sequenceName="hotel_sequence", initialValue = 28) + @SequenceGenerator(name = "hotel_generator", sequenceName = "hotel_sequence", initialValue = 28) @GeneratedValue(generator = "hotel_generator") private Long id; diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/Person.java b/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/Person.java index d807323b46..a304be0843 100644 --- a/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/Person.java +++ b/spring-boot-samples/spring-boot-sample-flyway/src/main/java/sample/flyway/Person.java @@ -24,7 +24,7 @@ import javax.persistence.SequenceGenerator; @Entity public class Person { @Id - @SequenceGenerator(name="person_generator", sequenceName="person_sequence", allocationSize = 1) + @SequenceGenerator(name = "person_generator", sequenceName = "person_sequence", allocationSize = 1) @GeneratedValue(generator = "person_generator") private Long id; private String firstName; diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Note.java b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Note.java index 9e2744b460..e23b50bfd7 100644 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Note.java +++ b/spring-boot-samples/spring-boot-sample-jpa/src/main/java/sample/jpa/domain/Note.java @@ -28,7 +28,7 @@ import javax.persistence.SequenceGenerator; public class Note { @Id - @SequenceGenerator(name="note_generator", sequenceName="note_sequence", initialValue = 5) + @SequenceGenerator(name = "note_generator", sequenceName = "note_sequence", initialValue = 5) @GeneratedValue(generator = "note_generator") private long id; diff --git a/spring-boot-samples/spring-boot-sample-oauth2-client/src/test/java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java b/spring-boot-samples/spring-boot-sample-oauth2-client/src/test/java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java index 51e0b422f0..377fbaf251 100644 --- a/spring-boot-samples/spring-boot-sample-oauth2-client/src/test/java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-oauth2-client/src/test/java/sample/oauth2/client/SampleOAuth2ClientApplicationTests.java @@ -57,10 +57,8 @@ public class SampleOAuth2ClientApplicationTests { ResponseEntity entity = this.restTemplate.getForEntity("/login", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()) - .contains("/oauth2/authorization/github-client-1"); - assertThat(entity.getBody()) - .contains("/oauth2/authorization/github-client-2"); + assertThat(entity.getBody()).contains("/oauth2/authorization/github-client-1"); + assertThat(entity.getBody()).contains("/oauth2/authorization/github-client-2"); } } diff --git a/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java b/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java index 825cae0024..016065d1cc 100644 --- a/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java @@ -49,8 +49,8 @@ public class SamplePropertyValidationApplicationTests { @Test public void bindValidProperties() { this.context.register(SamplePropertyValidationApplication.class); - TestPropertyValues.of("sample.host:192.168.0.1", - "sample.port:9090").applyTo(this.context); + TestPropertyValues.of("sample.host:192.168.0.1", "sample.port:9090") + .applyTo(this.context); this.context.refresh(); SampleProperties properties = this.context.getBean(SampleProperties.class); assertThat(properties.getHost()).isEqualTo("192.168.0.1"); @@ -60,8 +60,8 @@ public class SamplePropertyValidationApplicationTests { @Test public void bindInvalidHost() { this.context.register(SamplePropertyValidationApplication.class); - TestPropertyValues.of("sample.host:xxxxxx", - "sample.port:9090").applyTo(this.context); + TestPropertyValues.of("sample.host:xxxxxx", "sample.port:9090") + .applyTo(this.context); this.thrown.expect(BeanCreationException.class); this.thrown.expectMessage("Failed to bind properties under 'sample'"); this.context.refresh(); @@ -79,8 +79,8 @@ public class SamplePropertyValidationApplicationTests { public void validatorOnlyCalledOnSupportedClass() { this.context.register(SamplePropertyValidationApplication.class); this.context.register(ServerProperties.class); // our validator will not apply - TestPropertyValues.of("sample.host:192.168.0.1", - "sample.port:9090").applyTo(this.context); + TestPropertyValues.of("sample.host:192.168.0.1", "sample.port:9090") + .applyTo(this.context); this.context.refresh(); SampleProperties properties = this.context.getBean(SampleProperties.class); assertThat(properties.getHost()).isEqualTo("192.168.0.1");