diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/config/AbstractDataSourceProperties.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/config/AbstractDataSourceProperties.java index 59373a744..0f74084eb 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/config/AbstractDataSourceProperties.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/config/AbstractDataSourceProperties.java @@ -19,7 +19,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; public class AbstractDataSourceProperties { private String dataType = "json"; - private String ruleType; + private RuleType ruleType; private String converterClass; @JsonIgnore protected String factoryBeanName; @@ -36,11 +36,11 @@ public class AbstractDataSourceProperties { this.dataType = dataType; } - public String getRuleType() { + public RuleType getRuleType() { return ruleType; } - public void setRuleType(String ruleType) { + public void setRuleType(RuleType ruleType) { this.ruleType = ruleType; } @@ -61,15 +61,10 @@ public class AbstractDataSourceProperties { } public void preCheck(String dataSourceName) { - if (!RuleType.getByName(this.getRuleType()).isPresent()) { - throw new IllegalArgumentException( - "[Sentinel Starter] DataSource " + dataSourceName - + " get error ruleType [" + this.getRuleType() + "]"); - } } public void postRegister(AbstractDataSource dataSource) { - switch (RuleType.getByName(this.getRuleType()).get()) { + switch (this.getRuleType()) { case FLOW: FlowRuleManager.register2Property(dataSource.getProperty()); break; diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/config/NacosDataSourceProperties.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/config/NacosDataSourceProperties.java index a71b31231..1b49ac76b 100644 --- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/config/NacosDataSourceProperties.java +++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/config/NacosDataSourceProperties.java @@ -128,10 +128,10 @@ public class NacosDataSourceProperties extends AbstractDataSourceProperties { .getProperty(SentinelDataSourceConstants.PROJECT_NAME) + "-" + type); result.setGroupId("nacos-sentinel"); if (type.equals(RuleType.FLOW.getName())) { - result.setRuleType(RuleType.FLOW.getName()); + result.setRuleType(RuleType.FLOW); } else { - result.setRuleType(RuleType.DEGRADE.getName()); + result.setRuleType(RuleType.DEGRADE); } return result; } diff --git a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelDataSourceHandler.java b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelDataSourceHandler.java index f1a651126..f9776d275 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelDataSourceHandler.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelDataSourceHandler.java @@ -18,7 +18,6 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.cloud.alibaba.sentinel.SentinelConstants; import org.springframework.cloud.alibaba.sentinel.SentinelProperties; -import org.springframework.cloud.alibaba.sentinel.datasource.RuleType; import org.springframework.cloud.alibaba.sentinel.datasource.SentinelDataSourceConstants; import org.springframework.cloud.alibaba.sentinel.datasource.config.AbstractDataSourceProperties; import org.springframework.cloud.alibaba.sentinel.datasource.config.DataSourcePropertiesConfiguration; @@ -199,7 +198,7 @@ public class SentinelDataSourceHandler { // 'sentinel-{converterType}-{ruleType}-converter' builder.addPropertyReference("converter", "sentinel-" + propertyValue.toString() + "-" - + dataSourceProperties.getRuleType() + + dataSourceProperties.getRuleType().getName() + "-converter"); } } @@ -220,7 +219,7 @@ public class SentinelDataSourceHandler { .getBean(dataSourceName); logAndCheckRuleType(newDataSource, dataSourceName, - RuleType.getByName(dataSourceProperties.getRuleType()).get().getClazz()); + dataSourceProperties.getRuleType().getClazz()); // register property in RuleManager dataSourceProperties.postRegister(newDataSource);