一.dubbo注解配置
1.首先配置registryConfig 注冊(cè)中心
2.配置applictionConifg 和 consumerConfig/providerConfig配置(可選)
3.配置dubbo 注解掃描包
4.使用@Service,@Reference注解消費(fèi)者提供者
@Configuration
public class DubboConfiguration {
@Bean
public ApplicationConfig applicationConfig() {
ApplicationConfig applicationConfig = new ApplicationConfig();
applicationConfig.setName("provider-test");
return applicationConfig;
}
@Bean
public RegistryConfig registryConfig() {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("zookeeper://127.0.0.1:2181");
registryConfig.setClient("curator");
return registryConfig;
}
}
配置完基礎(chǔ)設(shè)置后,配置掃描路徑
@SpringBootApplication
@DubboComponentScan(basePackages = "com.alibaba.dubbo.test.service.impl")
public class ProviderTestApp {
// ...
}
使用注解標(biāo)記
public class AnnotationConsumeService {
@com.alibaba.dubbo.config.annotation.Reference
public AnnotateService annotateService;
// ...
}
注解屬性與配置文件方式一致。
二.dubbo關(guān)閉啟動(dòng)檢查
<dubbo:reference interface="com.foo.BarService" check="false" />
dubbo.reference.com.foo.BarService.check=false
java -Ddubbo.reference.com.foo.BarService.check=false
dubbo默認(rèn)是在啟動(dòng)時(shí),檢查我所引用的服務(wù)接口是否存在,如果不存在即拋出異常。所以都是先啟動(dòng)提供者,再啟動(dòng)消費(fèi)者。但是有些情況是可以不在啟動(dòng)時(shí)候,檢查。
1.spring容器是懶加載的
2.使用代碼API方式延遲加載
3.存在循環(huán)依賴的情況
這些情況都可以關(guān)閉啟動(dòng)檢查
優(yōu)先級(jí)為:jvm 參數(shù) > xml > properties