Springboot 使用eureka

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/nanruitao10/article/details/85164923

在pom中添加依赖:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
    </dependencies>

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

配置yml文件:

spring:
  application:
    name: eureka-server
server:
  port: 6082

eureka:
  instance:
    hostname: master
  client:
    #register-with-eureka: false
    #fetch-registry: false
    serviceUrl:
      defaultZone: http://localhost:6081/eureka/

在启动类中增加@EnableEurekaServer:

@EnableEurekaServer
@SpringBootApplication
public class EurekaMasterApplication {

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

git地址:https://github.com/nanrt/eureka-master.git

猜你喜欢

转载自blog.csdn.net/nanruitao10/article/details/85164923