完全用注解替换掉之前的部分配置文件
项目结构
下面给出服务的的部分代码
- [DubboConfiguration]
@Configuration
@EnableDubbo(scanBasePackages = "com.xh.dubbo.learn.lesson1.provider.service.impl")
public class DubboConfiguration {
@Bean
public ApplicationConfig getApplicationConfig() {
ApplicationConfig applicationConfig = new ApplicationConfig();
applicationConfig.setName("sesson1-config-provider");
return applicationConfig;
}
@Bean // #1
public ProviderConfig providerConfig() {
ProviderConfig providerConfig = new ProviderConfig();
providerConfig.setTimeout(1000);
return providerConfig;
}
@Bean // #3
public RegistryConfig registryConfig() {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setProtocol("zookeeper");
registryConfig.setAddress("zookeeper://127.0.0.1:2181");
registryConfig.setPort(2181);
return registryConfig;
}
@Bean // #4
public ProtocolConfig protocolConfig() {
ProtocolConfig protocolConfig = new ProtocolConfig();
protocolConfig.setName("dubbo");
protocolConfig.setPort(20880);
return protocolConfig;
}
}
- [ProviderApp]
@RestController
@SpringBootApplication
public class ProviderApp {
@GetMapping("/hello")
public String hello() {
return "hello";
}
public static void main(String[] args) throws IOException {
//SpringApplication.run(ProviderApp.class, args);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DubboConfiguration.class);
context.start();
System.in.read();
}
}