Spring Cloud Eureka Client 配置

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">
    <parent>
        <artifactId>SpringCloudFoundationartifactId>
        <groupId>com.springcloudgroupId>
        <version>1.0-SNAPSHOTversion>
    parent>
    <modelVersion>4.0.0modelVersion>
    <artifactId>eurekaclientartifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-netflix-eureka-clientartifactId>
            <version>2.0.2.RELEASEversion>
        dependency>
    dependencies>
project>

bootstrap.properties 配置

server.port=8010
# 当前服务注册在 Eureka Server 上的名称
spring.application.name=provider
# 注册中心的访问地址
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
# 是否将当前服务的 IP 注册到 Eureka Server
eureka.instance.prefer-ip-address=true

启动类跟 Spring Boot 的一样

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

测试

在启动 EurekaServerApplication 后启动 ProviderApplicaiton,进入 http://localhost:8761 会显示 PROVIDER 则成功。
Spring Cloud Eureka Client 配置_第1张图片

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