1. 程式人生 > >SpringCloud第二篇 eureka(服務註冊中心)

SpringCloud第二篇 eureka(服務註冊中心)

1.新建一個Spring Cloud的eureka專案

2.具體的pom如下

<?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>com.star.guo</groupId>
        <artifactId>springcloudversion</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <!-- <groupId>com.star.guo</groupId> -->
    <artifactId>eureka</artifactId>
    <!-- <version>0.0.1-SNAPSHOT</version> -->
    <packaging>jar</packaging>
    <name>eureka</name>
    <description>Spring Cloud專案</description>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>


</project>
 

3.添加註釋

@EnableEurekaServer

4.新增配置,我因比較習慣yml,曾經過渡的時候也不太習慣,故繼續使用yml

application.properties修改為application.yml

server:
  port: 8000

eureka:
  instance:
    hostname: localhost
  client:
#防止registerWithEureka和 fetchRegistry自己去註冊自己,故設為false,用於註冊中心
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

spring:
  application:
    name: eurka-server

 

5.啟動並檢視

http://localhost:8000