1.pom.xml 添加相关依赖。dubbo选择2.5.7及以上版本
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.7</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.9</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
2. 添加配置dubbo的Configuration类
@Configuration
public class ProfileConsumerDubboConfiguration {
@Autowired
private ProfileProperties config;
@Bean(name = "profileApplicationConfig")
public ApplicationConfig applicationConfig(){
ApplicationConfig applicationConfig = new ApplicationConfig();
applicationConfig.setName("profile-present-service");
applicationConfig.setOwner("profile");
applicationConfig.setOrganization("touna");
return applicationConfig;
}
@Bean(name = "profileConsumerConfig")
public ConsumerConfig consumerConfig() {
ConsumerConfig consumerConfig = new ConsumerConfig();
consumerConfig.setTimeout(config.getTimeout());
return consumerConfig;
}
@Bean(name = "profileRegistryConfig")
public RegistryConfig registryConfig() {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress(config.getAddress());
registryConfig.setClient("curator");
return registryConfig;
}
@Bean
public ProfileVariableConfService profileVariableConfService(){
ReferenceConfig<ProfileVariableConfService> reference = new ReferenceConfig<>();
reference.setApplication(applicationConfig());
reference.setRegistry(registryConfig());
reference.setInterface(ProfileVariableConfService.class);
return reference.get();
}
}