From a7e56f9f81e3b37d0953bf1dc69f56a815c7f86b Mon Sep 17 00:00:00 2001 From: ooooooook Date: Sun, 29 Sep 2024 16:35:59 +0800 Subject: [PATCH] Optimize TracingProperties (#2438) * optimize TracingProperties * optimize ElasticJobTracingConfiguration * fix the code formatting issues --------- Co-authored-by: cheyx --- .../boot/tracing/ElasticJobTracingConfiguration.java | 7 ++++--- .../elasticjob/spring/boot/tracing/TracingProperties.java | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spring/boot-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/ElasticJobTracingConfiguration.java b/spring/boot-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/ElasticJobTracingConfiguration.java index 6ed0edfba3..262f117ba3 100644 --- a/spring/boot-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/ElasticJobTracingConfiguration.java +++ b/spring/boot-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/ElasticJobTracingConfiguration.java @@ -21,7 +21,6 @@ import org.apache.shardingsphere.elasticjob.kernel.tracing.config.TracingConfiguration; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -68,9 +67,11 @@ public DataSource tracingDataSource(final TracingProperties tracingProperties) { * @return a bean of tracing configuration */ @Bean - @ConditionalOnBean(DataSource.class) - public TracingConfiguration tracingConfiguration(@Qualifier("dataSource") final DataSource dataSource, + public TracingConfiguration tracingConfiguration(@Qualifier("dataSource") @Nullable final DataSource dataSource, @Qualifier("tracingDataSource") @Nullable final DataSource tracingDataSource) { + if (dataSource == null && tracingDataSource == null) { + throw new IllegalArgumentException("Neither dataSource nor tracingDataSource bean is required"); + } return new TracingConfiguration<>("RDB", null == tracingDataSource ? dataSource : tracingDataSource); } } diff --git a/spring/boot-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/TracingProperties.java b/spring/boot-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/TracingProperties.java index d34fc18cb9..479dae86cc 100644 --- a/spring/boot-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/TracingProperties.java +++ b/spring/boot-starter/src/main/java/org/apache/shardingsphere/elasticjob/spring/boot/tracing/TracingProperties.java @@ -21,6 +21,7 @@ import lombok.Setter; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.NestedConfigurationProperty; import java.util.HashSet; import java.util.Set; @@ -32,6 +33,7 @@ public class TracingProperties { private String type; + @NestedConfigurationProperty private DataSourceProperties dataSource; private Set includeJobNames = new HashSet<>();