“Eureka Client 演示”的版本间的差异

来自姬鸿昌的知识库
跳到导航 跳到搜索
 
(未显示同一用户的2个中间版本)
第44行: 第44行:
 
     </dependencies>
 
     </dependencies>
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
=== 配置文件 ===
 +
 +
==== application.yml ====
 +
<syntaxhighlight lang="yaml">
 +
spring:
 +
  application:
 +
    # 如果没有配置,默认名称 UNKNOWN
 +
    name: demo
 +
 +
eureka:
 +
  client:
 +
    service-url:
 +
      # 下面信息也是默认值
 +
      defaultZone: http://localhost:8761/eureka/
 +
</syntaxhighlight>
 +
 +
==== spring.application.name ====
 +
[[文件:Spring.application.name.png|无|缩略图|624x624像素]]
 +
 +
 +
 +
==== eureka.client.service-url.defaultZone ====
 +
[[文件:Eureka.client.service-url.defaultZone.png|无|缩略图|1023x1023像素]]
 +
 +
 +
==== 注意 ====
 +
如果要变更 Eureka Server 的注册地址的端口号,只修改 <code>server.port</code> 是不够的,还要保证 <code>eureka.client.service-url.defalutZone</code> 一致<syntaxhighlight lang="yaml">
 +
eureka:
 +
  client:
 +
    # 因为当前项目为服务,不需要向服务注册自己,默认为 true
 +
    register-with-eureka: false
 +
    # 因为当前为非集群版 eureka,所以不需要同步其他节点数据
 +
    fetch-registry: false
 +
    # 当 server.port 配置不是 8761 时需要配置内容
 +
    service-url:
 +
      defalutZone: http://localhost:8088/eureka/
 +
 +
# 如果不配置8761,还需要配置 defaultZone 修改端口
 +
server:
 +
  port: 8088
 +
</syntaxhighlight>
 +
 +
 +
https://github.com/jihch/eureka-client

2023年3月11日 (六) 02:32的最新版本

https://www.bilibili.com/video/BV1eU4y187zE/?p=11

Eureka Client 可以向 Eureka Server 中注册自己

导入依赖

注意依赖换成了 Eureka 客户端依赖

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
    </parent>

    <groupId>io.github.jihch</groupId>
    <artifactId>eureka-client</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <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>
    </dependencies>


配置文件

application.yml

spring:
  application:
    # 如果没有配置,默认名称 UNKNOWN
    name: demo

eureka:
  client:
    service-url:
      # 下面信息也是默认值
      defaultZone: http://localhost:8761/eureka/

spring.application.name

Spring.application.name.png


eureka.client.service-url.defaultZone

Eureka.client.service-url.defaultZone.png


注意

如果要变更 Eureka Server 的注册地址的端口号,只修改 server.port 是不够的,还要保证 eureka.client.service-url.defalutZone 一致

eureka:
  client:
    # 因为当前项目为服务,不需要向服务注册自己,默认为 true
    register-with-eureka: false
    # 因为当前为非集群版 eureka,所以不需要同步其他节点数据
    fetch-registry: false
    # 当 server.port 配置不是 8761 时需要配置内容
    service-url:
      defalutZone: http://localhost:8088/eureka/

# 如果不配置8761,还需要配置 defaultZone 修改端口
server:
  port: 8088


https://github.com/jihch/eureka-client