美文网首页
4.服务治理-Eureka-启动程序

4.服务治理-Eureka-启动程序

作者: 溅十三 | 来源:发表于2020-04-16 23:05 被阅读0次

1.pom.xml

<?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.imooc</groupId>
    <artifactId>spring-cloud-demo</artifactId>
    <version>1.0-SNAPSHOT</version>
<!--    dependencyManagement管理子类的依赖版本-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-start-parent</artifactId>
                <version>2.1.5.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
<!--                自动生成一些代码-->
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.18</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
<!--                    配置项,行为-->
                    <source>1.8</source>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

2.启动类实现

package com.imooc.springcloud;

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
    //1.添加main方法,启动一个springBoot和spring运用都是通过main方法
    //2.添加springBoot和eureka的注解,EurekaServerApplication启动类就会被识别为eureka的注册中心
    //3.给启动类添加一个启动方法new SpringApplicationBuilder(EurekaServerApplication.class)
    //4.定义启动方式.web(WebApplicationType.SERVLET)
    //5.调用run方法
    public static void main(String[] args) {
        new SpringApplicationBuilder(EurekaServerApplication.class)
                .web(WebApplicationType.SERVLET)
                .run(args);
    }
}

3.application.properties

#应用叫什么名字
spring.application.name=eureka-server 

server.port=20000
#eureka本地才是
eureka.instance.hostname=127.0.0.1
#是否发起服务注册?注册中心,不需要自己注册自己
eureka.client.register-with-eureka=false
#是否去拉取服务注册表?注册中心,不需要拉取服务注册表
eureka.client.fetch-registry=false

4.启动程序

访问http://127.0.0.1:20000成功

相关文章

网友评论

      本文标题:4.服务治理-Eureka-启动程序

      本文链接:https://www.haomeiwen.com/subject/lsjjvhtx.html