SpringCloud开发实例--Eureka 服务注册中心

创建工程(eureka注册中心)

新建SpringBoot工程
SpringCloud开发实例--Eureka 服务注册中心_第1张图片

选择依赖的组建

SpringCloud开发实例--Eureka 服务注册中心_第2张图片

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.0modelVersion>
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.1.6.RELEASEversion>
        <relativePath/> 
    parent>
    <groupId>com.dowheregroupId>
    <artifactId>springcloud_eureka_server_demo1artifactId>
    <version>0.0.1-SNAPSHOTversion>
    <name>springcloud_eureka_server_demo1name>
    <description>eureka注册中心 for Spring Bootdescription>

    <properties>
        <java.version>1.8java.version>
        <spring-cloud.version>Greenwich.SR1spring-cloud.version>
    properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-netflix-eureka-serverartifactId>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-devtoolsartifactId>
            <scope>runtimescope>
            <optional>trueoptional>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>
    dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloudgroupId>
                <artifactId>spring-cloud-dependenciesartifactId>
                <version>${spring-cloud.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>
        dependencies>
    dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
        plugins>
    build>

project>

修改application.yml

server:
  port: 8080
eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

修改启动类

SpringcloudEurekaServerDemo1Application.java,主要是添加@EnableEurekaServer注解,表示为eureka注册中心。

package com.dowhere;

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

@EnableEurekaServer
@SpringBootApplication
public class SpringcloudEurekaServerDemo1Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringcloudEurekaServerDemo1Application.class, args);
    }

}

启动工程

打开浏览器输入http://localhost:8080/,看到如下页面表示eureka注册中心启动成功。
SpringCloud开发实例--Eureka 服务注册中心_第3张图片

你可能感兴趣的:(java,Spring,SpringCloud)