Code
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
Code
# Spring boot application
spring.application.name = dubbo-provider-demo
server.port = 9090
management.port = 9091
# Base packages to scan Dubbo Components (e.g., @Service, @Reference)
dubbo.scan.basePackages = com.alibaba.boot.dubbo.demo.provider.service
# Dubbo Config properties
## ApplicationConfig Bean
dubbo.application.id = dubbo-provider-demo
dubbo.application.name = dubbo-provider-demo
## ProtocolConfig Bean
dubbo.protocol.id = dubbo
dubbo.protocol.name = dubbo
dubbo.protocol.port = 12345
## RegistryConfig Bean
dubbo.registry.id = my-registry
dubbo.registry.address = N/A
java
@SpringBootApplication
@EnableDubboConfiguration
public class DubboProviderLauncher {
//...
}
java
@Service(interfaceClass = IHelloService.class)
@Component
public class HelloServiceImpl implements IHelloService {
//...
}
==注意:实体类必须实现Serializable接口==
同上
Code
# Spring boot application
spring.application.name = dubbo-provider-demo
# Dubbo Config properties
## ApplicationConfig Bean
dubbo.application.id = dubbo-consumer-demo
dubbo.application.name = dubbo-consumer-demo
## ProtocolConfig Bean
dubbo.protocol.id = dubbo
dubbo.protocol.name = dubbo
dubbo.protocol.port = 12345
java
@SpringBootApplication
@EnableDubboConfiguration
public class DubboConsumerLauncher {
//...
}
java
@RestController
public class DubboConsumer {
@Reference(url = "dubbo://127.0.0.1:20880")
private HseCustomerService customerService;
@GetMapping("list2")
public Object getList(@RequestParam(defaultValue = "0")Integer fromId,
@RequestParam(defaultValue = "2")Integer limit ){
//初始化page插件,传入分页参数
PageHelper.startPage(fromId,limit);
List<HseCustomer> list = customerService.getList();
//包装想要返回的结果,包含多种信息
PageInfo pageInfo = new PageInfo(list);
return pageInfo;
}
}