From 74376aa023c9e08b49210cc4f7f1b1688d1243b0 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 29 Nov 2018 15:30:28 -0800 Subject: [PATCH 1/2] Polish --- .../HikariDataSourceMetricsPostProcessor.java | 15 +++++++++------ .../WebMvcMetricsAutoConfiguration.java | 3 +++ .../jersey/JerseyAutoConfiguration.java | 18 ++++++++---------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/HikariDataSourceMetricsPostProcessor.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/HikariDataSourceMetricsPostProcessor.java index 89f3d6e5f8d..87278712e81 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/HikariDataSourceMetricsPostProcessor.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/HikariDataSourceMetricsPostProcessor.java @@ -59,17 +59,15 @@ class HikariDataSourceMetricsPostProcessor implements BeanPostProcessor, Ordered } private HikariDataSource determineHikariDataSource(Object bean) { - if (!(bean instanceof DataSource)) { - return null; + if (bean instanceof DataSource) { + return DataSourceUnwrapper.unwrap((DataSource) bean, HikariDataSource.class); } - DataSource dataSource = (DataSource) bean; - return DataSourceUnwrapper.unwrap(dataSource, HikariDataSource.class); + return null; } private void bindMetricsRegistryToHikariDataSource(MeterRegistry registry, HikariDataSource dataSource) { - if (dataSource.getMetricRegistry() == null - && dataSource.getMetricsTrackerFactory() == null) { + if (!hasExisingMetrics(dataSource)) { try { dataSource.setMetricsTrackerFactory( new MicrometerMetricsTrackerFactory(registry)); @@ -80,6 +78,11 @@ class HikariDataSourceMetricsPostProcessor implements BeanPostProcessor, Ordered } } + private boolean hasExisingMetrics(HikariDataSource dataSource) { + return dataSource.getMetricRegistry() != null + || dataSource.getMetricsTrackerFactory() != null; + } + private MeterRegistry getMeterRegistry() { if (this.meterRegistry == null) { this.meterRegistry = this.context.getBean(MeterRegistry.class); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.java index 2c6aef80025..5fd587de80f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.java @@ -105,6 +105,9 @@ public class WebMvcMetricsAutoConfiguration { return new MetricsWebMvcConfigurer(meterRegistry, tagsProvider); } + /** + * {@link WebMvcConfigurer} to add metrics interceptors. + */ static class MetricsWebMvcConfigurer implements WebMvcConfigurer { private final MeterRegistry meterRegistry; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java index f3cf0bab3b3..9babf787636 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java @@ -109,16 +109,6 @@ public class JerseyAutoConfiguration implements ServletContextAware { customize(); } - private String resolveApplicationPath() { - if (StringUtils.hasLength(this.jersey.getApplicationPath())) { - return this.jersey.getApplicationPath(); - } - else { - return findApplicationPath(AnnotationUtils.findAnnotation( - this.config.getApplication().getClass(), ApplicationPath.class)); - } - } - private void customize() { if (this.customizers != null) { AnnotationAwareOrderComparator.sort(this.customizers); @@ -134,6 +124,14 @@ public class JerseyAutoConfiguration implements ServletContextAware { return this::resolveApplicationPath; } + private String resolveApplicationPath() { + if (StringUtils.hasLength(this.jersey.getApplicationPath())) { + return this.jersey.getApplicationPath(); + } + return findApplicationPath(AnnotationUtils.findAnnotation( + this.config.getApplication().getClass(), ApplicationPath.class)); + } + @Bean @ConditionalOnMissingBean public FilterRegistrationBean requestContextFilter() { From 893d5666becc48ffa333a583bdee3d935ab5c886 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 29 Nov 2018 15:30:51 -0800 Subject: [PATCH 2/2] Update copyright year for changed files --- .../boot/test/autoconfigure/web/reactive/WebFluxTest.java | 2 +- .../autoconfigure/web/reactive/webclient/JsonController.java | 2 +- .../webclient/WebFluxTestAllControllersIntegrationTests.java | 2 +- .../webclient/WebFluxTestAutoConfigurationIntegrationTests.java | 2 +- .../boot/devtools/tests/LaunchedApplication.java | 2 +- .../boot/devtools/tests/LocalApplicationLauncher.java | 2 +- .../boot/devtools/tests/RemoteApplicationLauncher.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTest.java index 1d2d0e4a13e..11662b7f459 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTest.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-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/JsonController.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/JsonController.java index ac754cd5d20..bb05fa23b7e 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/JsonController.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/JsonController.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-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebFluxTestAllControllersIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebFluxTestAllControllersIntegrationTests.java index d9f865dffc2..c7e3bf4d664 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebFluxTestAllControllersIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebFluxTestAllControllersIntegrationTests.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-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebFluxTestAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebFluxTestAutoConfigurationIntegrationTests.java index 85d9ad27d87..d7ff3472525 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebFluxTestAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebFluxTestAutoConfigurationIntegrationTests.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-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/LaunchedApplication.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/LaunchedApplication.java index e8eb2f43364..dc1b50d8b93 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/LaunchedApplication.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/LaunchedApplication.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-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/LocalApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/LocalApplicationLauncher.java index e176be122ca..867a59fe63d 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/LocalApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/LocalApplicationLauncher.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-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/RemoteApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/RemoteApplicationLauncher.java index 92840d4d5de..ac77e6c847f 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/RemoteApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/RemoteApplicationLauncher.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.