• 创建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;
        }
    }

     

  • 相关阅读:
    NWERC 2016 F. Free Weights
    Gym 101142C CodeCoder vs TopForces 【dfs】
    HDU 6186 number number number 【规律+矩阵快速幂】
    UVA 10048 Audiophobia 【floyd】
    Fully Connected Layer:全连接层
    Artificial Neural Networks:人工神经网络
    Back Propagation:误差反向传播算法
    Gradient Descent:梯度下降
    Regularization:正则化
    softmax loss function:归一化指数函数
  • 原文地址:https://www.cnblogs.com/mingforyou/p/15426869.html
Copyright © 2020-2023  润新知