• springcloud-服务消费者者注册进consul


      1.创建模块

      2.改pom.xml

     <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-consul-discovery</artifactId>
            </dependency>
            <dependency>
                <groupId>cn.aib.springcloud</groupId>
                <artifactId>springclud-api-common</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <scope>runtime</scope>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>

      3.改配置

    server:
      port: 80
    
    # 服务别名---zookeeper注册中心名称
    spring:
      application:
        name: consul-consumer-payment
      cloud:
        consul:
          host: localhost
          port: 8500
          discovery:
            service-name: ${spring.application.name}

      4.主启动

    @SpringBootApplication
    @EnableDiscoveryClient
    public class OrderConsulApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(OrderConsulApplication.class, args);
        }
    }

      5.写业务

    @RestController
    public class OrderController {
    
        //支付服务地址
        public static final String ZK_URL = "http://consul-provider-payment";
    
        @Resource
        private RestTemplate restTemplate;
    
        @GetMapping("/consumer/payment/consul")
        public String getpaymentInfo(){
    
            String returnValue = restTemplate.getForObject(ZK_URL+"/payment/consul", String.class);
    
            return returnValue;
        }
    }

      6.测试

  • 相关阅读:
    MySQL实现嵌套集合模型
    Go项目结构和模块导入
    sqlalchemy(二)高级用法
    sqlalchemy(一)基本操作
    K-均值聚类算法
    回归
    logistic回归
    Android隐藏状态栏、导航栏
    Android监听返回键、Home键+再按一次返回键退出应用
    PDFMate PDF Converter Pro
  • 原文地址:https://www.cnblogs.com/ibcdwx/p/14240101.html
Copyright © 2020-2023  润新知