第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

Spring cloud netfix 新手教程(2021版)| 第二篇 Eureka Client

標(biāo)簽:
Java Spring Cloud Spring

创建Good Service子模块

xml如下, spring-cloud-netflix-learn-common是项目的通用模块,一般 model entity ,fegin client, DTO等都放在这个模块中

<?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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.example</groupId>
        <artifactId>spring-cloud-netflix-learn</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>spring-cloud-netflix-learn-eureka-goodservice</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>spring-cloud-netflix-learn-common</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>

</project>

创建Controller返回Goods列表

package com.tubabaxuebiancheng.controller;

import com.tubabaxuebiancheng.entity.Good;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class GoodController {


    @Value("${server.port}")
    private String serverPort;
    @GetMapping("/goods")
    public List getGoods() {
        ArrayList<Good> goods = new ArrayList<>();
        goods.add(new Good(1, "商品1"+serverPort));
        goods.add(new Good(2, "商品2"+serverPort));
        goods.add(new Good(3, "商品1"+serverPort));
        return goods;
    }
}

配置properties

server.port=7101

#注册中心(Eureka Server)地址
eureka.client.service-url.defaultZone=http://localhost:7001/eureka/

#每2秒发送心跳告知注册中心服务还存活
eureka.instance.lease-renewal-interval-in-seconds=2

#告知注册中心如果10秒没有收到心跳就剔除服务
eureka.instance.lease-expiration-duration-in-seconds=10

# 客户端在注册时使用自己的IP而不是主机名,缺省:false
eureka.instance.prefer-ip-address=true

#服务实例id 必须保证唯一性,本例子中相同service用端口区分唯一性
eureka.instance.instance-id=netflix-learn-good-application-${server.port}


spring.application.name=good-application


management.endpoints.web.exposure.include=*

在主启动类上通过@EnableEurekaClient开启Eureka Client

package com.tubabaxuebiancheng;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableEurekaClient
public class GoodApplication {

    public static void main(String[] args) {
        org.springframework.boot.SpringApplication.run(GoodApplication.class, args);
    }
}

启动Good Service

file

Good Service已经注册到Eureka Server上

file

本文由博客一文多发平台 OpenWrite 发布!

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報(bào)

0/150
提交
取消