Skip to content

Commit

Permalink
optimize ElasticJobTracingConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
cheyx committed Sep 24, 2024
1 parent 12b19da commit bc3dc8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
@Setter
@ConfigurationProperties(prefix = "elasticjob")
public class ElasticJobProperties {

private Map<String, ElasticJobConfigurationProperties> jobs = new LinkedHashMap<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,11 +36,11 @@
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(TracingProperties.class)
public class ElasticJobTracingConfiguration {

@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(name = "elasticjob.tracing.type", havingValue = "RDB")
static class RDBTracingConfiguration {

/**
* Create a bean of tracing DataSource.
*
Expand All @@ -59,7 +58,7 @@ public DataSource tracingDataSource(final TracingProperties tracingProperties) {
BeanUtils.copyProperties(dataSource, tracingDataSource);
return tracingDataSource;
}

/**
* Create a bean of tracing configuration.
*
Expand All @@ -68,9 +67,11 @@ public DataSource tracingDataSource(final TracingProperties tracingProperties) {
* @return a bean of tracing configuration
*/
@Bean
@ConditionalOnBean(DataSource.class)
public TracingConfiguration<DataSource> tracingConfiguration(@Qualifier("dataSource") final DataSource dataSource,
public TracingConfiguration<DataSource> 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);
}
}
Expand Down

0 comments on commit bc3dc8b

Please sign in to comment.