Consul 服务注册与发现02—— 服务提供者
生活随笔
收集整理的這篇文章主要介紹了
Consul 服务注册与发现02—— 服务提供者
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>dym_cloud2021</artifactId><groupId>com.atguigu.springcloud</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>cloud-providerconsul-payment8006</artifactId><dependencies><!-- 引入自己定義的api通用包,可以使用Payment支付Entity --><dependency><groupId>com.atguigu.springcloud</groupId><artifactId>cloud-api-commons</artifactId><version>${project.version}</version></dependency><!--SpringCloud consul-server --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-consul-discovery</artifactId></dependency><!-- SpringBoot整合Web組件 --><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><!--日常通用jar包配置--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>RELEASE</version><scope>test</scope></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>RELEASE</version><scope>test</scope></dependency></dependencies></project>application.yml
###consul服務端口號 server:port: 8006spring:application:name: consul-provider-payment####consul注冊中心地址cloud:consul:host: localhostport: 8500discovery:#hostname: 127.0.0.1service-name: ${spring.application.name}PaymentMain8006.java
package com.dym.springcloud;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;@SpringBootApplication @EnableDiscoveryClient public class PaymentMain8006 {public static void main(String[] args) {SpringApplication.run(PaymentMain8006.class,args);} }PaymentController.java
package com.dym.springcloud.controller;import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import java.util.UUID;@RestController @Slf4j public class PaymentController {@Value("${server.port}")private String serverPort;@RequestMapping(value = "/payment/consul")public String paymentConsul(){return "springcloud with consul: "+serverPort+"\t "+ UUID.randomUUID().toString();} }總結
以上是生活随笔為你收集整理的Consul 服务注册与发现02—— 服务提供者的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Consul 服务注册与发现01——简介
- 下一篇: Consul 服务注册与发现03—— 服