springcloud之注册中心eureka 环境搭建

一、新建一个maven工程

image.png


二、在pom.xml 中加入以下依赖

<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.cloud</groupId>

  <artifactId>bt-cloud</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <name>bt-cloud</name>

  <description>bt-cloud</description>

      <parent>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-parent</artifactId>

        <version>1.4.0.RELEASE</version> 

        <relativePath/>

    </parent>


    <properties>   

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

        <java.version>1.8</java.version>

    </properties>


    <dependencies>

        <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-starter-eureka-server</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-test</artifactId>

            <scope>test</scope>

        </dependency>

    </dependencies>


    <dependencyManagement>

        <dependencies>

            <dependency>

                <groupId>org.springframework.cloud</groupId>

                <artifactId>spring-cloud-dependencies</artifactId>

                <version>Camden.SR3</version>

                <type>pom</type>

                <scope>import</scope>

            </dependency>

        </dependencies>

    </dependencyManagement>



</project>


三、编写启动类

package com.bt.app;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.SpringBootConfiguration;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;


@EnableEurekaServer

@EnableAutoConfiguration

@SpringBootConfiguration

public class EurekaServerApp {

public static void main(String[] args) {

SpringApplication.run(EurekaServerApp.class, args);

}

}

注意:

@EnableEurekaServer

@EnableAutoConfiguration

这两个注意必须加入才能正常启动


四、在src/main/resources 下新建 application.yml,加入如下配置

server:

  port: 8761


eureka:

  instance:

    hostname: localhost

  client:

    registerWithEureka: false

    fetchRegistry: false

    serviceUrl:

      defaultZone:

http://${eureka.instance.hostname}:${server.port}/eureka/


五、启动EurekaServerApp类中的main 方法,控制台中输出如下

image.png



六、在浏览器中输入http://localhost:8761/


image.png


此时EurekaServer 注册中心搭建成功



猜你喜欢

转载自blog.51cto.com/4923168/2176439