Polish
This commit is contained in:
parent
fa84414421
commit
74376aa023
|
@ -59,17 +59,15 @@ class HikariDataSourceMetricsPostProcessor implements BeanPostProcessor, Ordered
|
||||||
}
|
}
|
||||||
|
|
||||||
private HikariDataSource determineHikariDataSource(Object bean) {
|
private HikariDataSource determineHikariDataSource(Object bean) {
|
||||||
if (!(bean instanceof DataSource)) {
|
if (bean instanceof DataSource) {
|
||||||
return null;
|
return DataSourceUnwrapper.unwrap((DataSource) bean, HikariDataSource.class);
|
||||||
}
|
}
|
||||||
DataSource dataSource = (DataSource) bean;
|
return null;
|
||||||
return DataSourceUnwrapper.unwrap(dataSource, HikariDataSource.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindMetricsRegistryToHikariDataSource(MeterRegistry registry,
|
private void bindMetricsRegistryToHikariDataSource(MeterRegistry registry,
|
||||||
HikariDataSource dataSource) {
|
HikariDataSource dataSource) {
|
||||||
if (dataSource.getMetricRegistry() == null
|
if (!hasExisingMetrics(dataSource)) {
|
||||||
&& dataSource.getMetricsTrackerFactory() == null) {
|
|
||||||
try {
|
try {
|
||||||
dataSource.setMetricsTrackerFactory(
|
dataSource.setMetricsTrackerFactory(
|
||||||
new MicrometerMetricsTrackerFactory(registry));
|
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() {
|
private MeterRegistry getMeterRegistry() {
|
||||||
if (this.meterRegistry == null) {
|
if (this.meterRegistry == null) {
|
||||||
this.meterRegistry = this.context.getBean(MeterRegistry.class);
|
this.meterRegistry = this.context.getBean(MeterRegistry.class);
|
||||||
|
|
|
@ -105,6 +105,9 @@ public class WebMvcMetricsAutoConfiguration {
|
||||||
return new MetricsWebMvcConfigurer(meterRegistry, tagsProvider);
|
return new MetricsWebMvcConfigurer(meterRegistry, tagsProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link WebMvcConfigurer} to add metrics interceptors.
|
||||||
|
*/
|
||||||
static class MetricsWebMvcConfigurer implements WebMvcConfigurer {
|
static class MetricsWebMvcConfigurer implements WebMvcConfigurer {
|
||||||
|
|
||||||
private final MeterRegistry meterRegistry;
|
private final MeterRegistry meterRegistry;
|
||||||
|
|
|
@ -109,16 +109,6 @@ public class JerseyAutoConfiguration implements ServletContextAware {
|
||||||
customize();
|
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() {
|
private void customize() {
|
||||||
if (this.customizers != null) {
|
if (this.customizers != null) {
|
||||||
AnnotationAwareOrderComparator.sort(this.customizers);
|
AnnotationAwareOrderComparator.sort(this.customizers);
|
||||||
|
@ -134,6 +124,14 @@ public class JerseyAutoConfiguration implements ServletContextAware {
|
||||||
return this::resolveApplicationPath;
|
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
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public FilterRegistrationBean<RequestContextFilter> requestContextFilter() {
|
public FilterRegistrationBean<RequestContextFilter> requestContextFilter() {
|
||||||
|
|
Loading…
Reference in New Issue