解决 dubbo 和 nacos 初始化顺序导致 循环初始化的问题
This commit is contained in:
@@ -28,15 +28,15 @@ dubbo:
|
|||||||
application:
|
application:
|
||||||
name: account-server
|
name: account-server
|
||||||
qos-port: 22221
|
qos-port: 22221
|
||||||
# qos-enable: true
|
qos-enable: true
|
||||||
registry:
|
registry:
|
||||||
address: nacos://121.40.109.122:8848 # Nacos 服务地址
|
address: nacos://121.40.109.122:8848 # Nacos 服务地址
|
||||||
group: server-dev
|
group: server-dev
|
||||||
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
# namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
||||||
protocol:
|
protocol:
|
||||||
port: 9101
|
port: 9101
|
||||||
threads: 20
|
threads: 20
|
||||||
threadpool: fixed
|
# threadpool: fixed
|
||||||
|
|
||||||
|
|
||||||
seata:
|
seata:
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ dubbo:
|
|||||||
registry:
|
registry:
|
||||||
address: nacos://121.40.109.122:8848 # Nacos 服务地址
|
address: nacos://121.40.109.122:8848 # Nacos 服务地址
|
||||||
group: server-dev
|
group: server-dev
|
||||||
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
# namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
|
||||||
protocol:
|
protocol:
|
||||||
port: 9401
|
port: 9401
|
||||||
threads: 20
|
threads: 20
|
||||||
threadpool: fixed
|
# threadpool: fixed
|
||||||
|
|
||||||
seata:
|
seata:
|
||||||
application-id: system-server
|
application-id: system-server
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.czg.config;
|
||||||
|
|
||||||
|
import org.apache.dubbo.config.ApplicationConfig;
|
||||||
|
import org.apache.dubbo.config.ProtocolConfig;
|
||||||
|
import org.apache.dubbo.config.RegistryConfig;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author GYJoker
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class CzgDubboBean {
|
||||||
|
|
||||||
|
private ApplicationConfig applicationConfig;
|
||||||
|
private ProtocolConfig protocolConfig;
|
||||||
|
|
||||||
|
@Value("${dubbo.application.name}")
|
||||||
|
private String applicationName;
|
||||||
|
|
||||||
|
@Value("${dubbo.application.qos-port}")
|
||||||
|
private Integer qosPort;
|
||||||
|
|
||||||
|
@Value("${dubbo.application.qos-enable}")
|
||||||
|
private Boolean qosEnable;
|
||||||
|
|
||||||
|
@Value("${dubbo.registry.address}")
|
||||||
|
private String registryAddress;
|
||||||
|
|
||||||
|
@Value("${dubbo.registry.group}")
|
||||||
|
private String registryGroup;
|
||||||
|
|
||||||
|
@Value("${dubbo.protocol.port}")
|
||||||
|
private Integer port;
|
||||||
|
|
||||||
|
@Value("${dubbo.protocol.threads}")
|
||||||
|
private Integer threads;
|
||||||
|
|
||||||
|
public CzgDubboBean() {
|
||||||
|
applicationConfig = new ApplicationConfig();
|
||||||
|
applicationConfig.setName(applicationName);
|
||||||
|
applicationConfig.setQosPort(qosPort);
|
||||||
|
applicationConfig.setQosEnable(qosEnable);
|
||||||
|
|
||||||
|
RegistryConfig registryConfig = new RegistryConfig();
|
||||||
|
registryConfig.setAddress(registryAddress);
|
||||||
|
registryConfig.setGroup(registryGroup);
|
||||||
|
|
||||||
|
protocolConfig = new ProtocolConfig();
|
||||||
|
protocolConfig.setPort(port);
|
||||||
|
protocolConfig.setThreads(threads);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApplicationConfig getApplicationConfig() {
|
||||||
|
return applicationConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProtocolConfig getProtocolConfig() {
|
||||||
|
return protocolConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.czg.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.DependsOn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author GYJoker
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@DependsOn("nacosConfigProperties") // 这里假设 Nacos 的配置属性 Bean 名为 nacosConfigProperties
|
||||||
|
public class DubboConfig {
|
||||||
|
// 这里可以添加 Dubbo 相关的配置 Bean
|
||||||
|
@Bean
|
||||||
|
public CzgDubboBean czgDubboBean() {
|
||||||
|
return new CzgDubboBean();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user