- demo 项目,增加 RPC 接口
This commit is contained in:
@@ -2,13 +2,25 @@ package cn.iocoder.mall.demo.application;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.config.ConfigFileApplicationListener;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.demo"})
|
||||
@EnableAsync(proxyTargetClass = true)
|
||||
//@PropertySource("classpath*:/application-dubbo.yaml")
|
||||
public class DemoApplication {
|
||||
|
||||
/**
|
||||
* 设置需要读取的配置文件的名字。
|
||||
* 基于 {@link org.springframework.boot.context.config.ConfigFileApplicationListener#CONFIG_NAME_PROPERTY} 实现。
|
||||
*/
|
||||
private static final String CONFIG_NAME_VALUE = "application,rpc,business";
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 设置环境变量
|
||||
System.setProperty(ConfigFileApplicationListener.CONFIG_NAME_PROPERTY, CONFIG_NAME_VALUE);
|
||||
|
||||
// 启动 Spring Boot 应用
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import cn.iocoder.mall.demo.application.convert.DemoProductConvert;
|
||||
import cn.iocoder.mall.demo.application.vo.DemoProductVO;
|
||||
import cn.iocoder.mall.demo.business.api.DemoProductService;
|
||||
import cn.iocoder.mall.demo.business.bo.product.DemoProductBO;
|
||||
import cn.iocoder.mall.demo.rpc.api.DemoProductRpcService;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -18,10 +20,20 @@ public class DemoProductController {
|
||||
@Autowired
|
||||
private DemoProductService productService;
|
||||
|
||||
@Reference(validation = "true", version = "${dubbo.consumer.DemoProductRpcService.version}")
|
||||
private DemoProductRpcService productRpcService;
|
||||
|
||||
@GetMapping("/get")
|
||||
public CommonResult<DemoProductVO> get(@RequestParam("id") Integer id) {
|
||||
DemoProductBO product = productService.get(id);
|
||||
return CommonResult.success(DemoProductConvert.INSTANCE.convert(product));
|
||||
}
|
||||
|
||||
// TODO 芋艿,这里只是做一个 demo 。实际一般不会这么玩,更多是内嵌的,像 {@link #get(Integer id)} 的情况。
|
||||
@GetMapping("/get2")
|
||||
public CommonResult<DemoProductVO> get2(@RequestParam("id") Integer id) {
|
||||
cn.iocoder.mall.demo.rpc.vo.DemoProductVO product = productRpcService.get(id);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
dubbo:
|
||||
application:
|
||||
name: demo-service
|
||||
registry:
|
||||
address: zookeeper://127.0.0.1:2181
|
||||
protocol:
|
||||
port: -1
|
||||
name: dubbo
|
||||
scan:
|
||||
base-packages: cn.iocoder.mall.demo.rpc.service
|
||||
consumer:
|
||||
DemoProductRpcService:
|
||||
version: 1.0.0
|
||||
@@ -1,3 +1,10 @@
|
||||
# spring
|
||||
spring:
|
||||
application:
|
||||
name: demo-application
|
||||
profiles:
|
||||
active: local
|
||||
|
||||
# server
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
Reference in New Issue
Block a user