zoukankan      html  css  js  c++  java
  • 创建SpringBoot分布式项目

     一、创建父项目

    pom.xml添加
    <packaging>pom</packaging>

    二、创建子项目   order、stock

    子项目pom.xml加上

        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
    <!--            <version>2.5.5</version>-->
            </dependency>
        </dependencies>

    设置端口  application.yml

    order

    server:
      port: 8010

    stock

    server:
      port: 8011

    启动项目

    package com.wsm.order;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.web.client.RestTemplateBuilder;
    import org.springframework.context.annotation.Bean;
    import org.springframework.web.client.RestTemplate;
    
    @SpringBootApplication
    public class OrderApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(OrderApplication.class,args);
        }
    
        @Bean
        public RestTemplate restTemplate(RestTemplateBuilder builder){
            RestTemplate restTemplate = builder.build();
            return restTemplate;
        }
    }
    package com.wsm.stock;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class StockApplication {
    
        public static void main(String[] args) {
    
            SpringApplication.run(StockApplication.class,args);
        }
    }
    package com.wsm.stock.controller;
    
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping("/stock")
    public class StockController {
    
        @RequestMapping("/reduct")
        public String reduct(){
            System.out.println("扣减库存");
            return "bbbbbccc";
        }
    }
    package com.wsm.order.controller;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    import org.springframework.web.client.RestTemplate;
    
    import javax.swing.*;
    
    @RestController
    @RequestMapping("/order")
    public class OrderController {
    
        @Autowired
        RestTemplate restTemplate;
    
        @RequestMapping("/add")
        public String add(){
            System.out.println("aaaaaaaaaaaaa");
            String msg = restTemplate.getForObject("http://localhost:8011/stock/reduct", String.class);
            return "hello world"+msg;
        }
    }

     

  • 相关阅读:
    C#编程思路
    将字符串类型字段转为map类型字段,使用str_to_map()函数
    写hive脚本时,如果hive的过滤条件比较多。可以把过滤条件放到一个参数里。然后把参数放到过滤条件处。这样以后只需要改参数就可以了
    linux中. 路径/文件
    inner join ,left join 会导致数据发散
    如何批量按分区插入数据
    hive表添加字段后,查不出数据是咋回事?
    linux中$0的含义
    linux中的$#含义
    linux的语法
  • 原文地址:https://www.cnblogs.com/mingforyou/p/15426869.html
Copyright © 2011-2022 走看看