1.eureka實戰-eurekaserver的啓動

1.idea裏新建一個工程,命名爲microservice-eureka,繼承自spring-boot-start-parent。html

2.pom.xml文件格式以下:java

<?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>

    <groupId>com.helloworld</groupId>
    <artifactId>microservice-eureka</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

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

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

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

 

3.在src/main/resources下面新建application.yml文件,加入以下內容。spring

server:
  port: 8761
eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false

4.在src/main/java 下新建包com.helloworld.eurekaapache

5.在com.helloworld.eureka包下新建類:EurekaServerapp

package com.helloworld.eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServer.class, args);
    }
}

 

6.運行EurekaServer類,啓動完成後訪問http://localhost:8761/,看到eureka server的頁面啓動完成了。maven

 

本篇文章完成了第一個springcloud程序eurekaserver註冊中心的啓動,下一篇文章將對上面的程序詳細講解。ide

相關文章
相關標籤/搜索