update 调整dubbo自定义负载均衡配置注入 使用spring自动注入

2.X
疯狂的狮子li 3 years ago
parent 529e025494
commit 6678ec6b7b

@ -0,0 +1,25 @@
package com.ruoyi.common.loadbalance.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
/**
* dubbo
*
* @author Lion Li
*/
public class CustomEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
System.setProperty("dubbo.consumer.loadbalance", "customDubboLoadBalancer");
}
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
}

@ -1,14 +1,12 @@
package com.ruoyi.common.loadbalance.config;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
import org.springframework.context.annotation.PropertySource;
/**
*
*
* @author Lion Li
*/
@PropertySource(value = "classpath:loadbalance.properties", encoding = "UTF-8")
@LoadBalancerClients(defaultConfiguration = CustomLoadBalanceClientConfiguration.class)
public class CustomLoadBalanceAutoConfiguration {

@ -1,2 +1,4 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.ruoyi.common.loadbalance.config.CustomLoadBalanceAutoConfiguration
org.springframework.boot.env.EnvironmentPostProcessor=\
com.ruoyi.common.loadbalance.config.CustomEnvironmentPostProcessor

@ -1 +0,0 @@
dubbo.consumer.loadbalance=customDubboLoadBalancer
Loading…
Cancel
Save