当前位置: 首页 > article >正文

分布式架构demo

1、外层创建pom

版本管理器

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.15</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

服务间调用 untitled1 调用 untitled2

  

 启动。。。。

untitled1   主要代码

@SpringBootApplication
public class Untitled1 {
    public static void main(String[] args) {
        SpringApplication.run(Untitled1.class,args);
        System.out.println("Hello world!");
    }

    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder){
        //官网建议构造器 构建一个builder 使用构造着设计模式 可是设置请求时间啥的

        RestTemplate restTemplate = builder.build();
        return  restTemplate;

    }
}

Controller 代码    

@RestController
@RequestMapping("/order")
public class Demo1Controller {
    @Autowired
    RestTemplate restTemplate;

    @PostMapping("/login")
    public String loging(){
        String msg= restTemplate.getForObject("http://localhost:8082/stock/reduct",String.class);
        return  "order"+msg;

    }

}

untitled2  Controller 代码

@RestController
@RequestMapping("/stock")
public class Demo1Controller {

    @GetMapping("/reduct")
    public String loging(){

        return  "扣减库存";

    }

}

http://www.kler.cn/a/152995.html

相关文章:

  • SpringBoot——Quartz 定时任务
  • 【BEV感知 LSS方案】Lift-Splat-Shoot(LSS)
  • js命名规则
  • acwing算法基础之动态规划--数位统计DP、状态压缩DP、树形DP和记忆化搜索
  • 这个sql有点东西,记录一下
  • FTP协议详解
  • React项目使用NProgress作为加载进度条
  • 从浏览器控制台发送get,post请求
  • 服务器和Linux ,安装R rstudio ,常用软件
  • 基于Java SSM移动电源租赁系统
  • Linux:strace 简介
  • 代码生成器——MyBatis Builder
  • js模块化的好处
  • Task.Run为什么会存在内存泄漏的风险?
  • Docker下安装Redis
  • 【算法每日一练]-图论(保姆级教程篇10 并查集)#POJ1988 #POJ1182
  • Python【走出棋盘】
  • MySQL数据库SQLSTATE[22007]: Invalid datetime format 日期类型不能为空值的解决办法
  • Swagger各版本访问地址
  • Linux命令——watch