1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

fix bug about sentinel commercialization

This commit is contained in:
fangjian0423 2018-12-19 23:43:00 +08:00
parent aaa68a04d5
commit 2a8f6e98c0

View File

@ -30,6 +30,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import com.alibaba.csp.sentinel.datasource.AbstractDataSource;
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
import com.alibaba.csp.sentinel.property.SentinelProperty;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
@ -253,7 +254,18 @@ public class SentinelDataSourceHandler {
beanFactory.registerBeanDefinition(dataSourceName, builder.getBeanDefinition());
// init in Spring
beanFactory.getBean(dataSourceName);
AbstractDataSource newDataSource = (AbstractDataSource) beanFactory
.getBean(dataSourceName);
// commercialization
if (!StringUtils.isEmpty(System.getProperties()
.getProperty(SentinelDataSourceConstants.NACOS_DATASOURCE_ENDPOINT))) {
if (dataSourceName.contains(SentinelConstants.FLOW_DATASOURCE_NAME)) {
FlowRuleManager.register2Property(newDataSource.getProperty());
}
else if (dataSourceName.contains(SentinelConstants.DEGRADE_DATASOURCE_NAME)) {
DegradeRuleManager.register2Property(newDataSource.getProperty());
}
}
dataSourceBeanNameList.add(dataSourceName);
}