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

猜你喜欢

转载自blog.csdn.net/guoxingege/article/details/84941044