Spring Eureka的使用入门

Eureka调度服务:

   Gradle依赖包:

基础框架依赖配置核心代码:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.14.RELEASE' }
    }
    
    afterEvaluate {Project  project -> 
        if (project.pluginManager.hasPlugin('java')) {
            configurations.all {
                resolutionStrategy.eachDependency {DependencyResolveDetails details -> 
                    forceVersion details, 'org.springframework.boot', '1.5.14.RELEASE'
                    forceVersion details, 'org.springframework.cloud:spring-cloud-dependencies', 'Edgware.SR4'
                    forceVersion details, 'org.slf4j', '1.7.21'
                }
                exclude module:'slf4j-log4j12'
                exclude module:'log4j'                
            }
            dependencies {testCompile 'junit:junit:4.12' }            
        }
    }

    repositories {
        mavenCentral()
    }

调度服务bulid.gralde:

apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

ext {
	springCloudVersion = 'Edgware.SR4'
}

dependencies {
    compile 'org.springframework.cloud:spring-cloud-starter-eureka-server'
    compile 'org.springframework:springloaded'
    compile 'org.springframework.boot:spring-boot-devtools'
}

dependencyManagement {
	imports {
		mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
	}
}

服务启动类:

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

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

app.yml配置:

server:
  port: 8761

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

启动服务,访问http://127.0.0.1:8761/eureka

注册中心启动完成;

原文地址:https://www.cnblogs.com/liangblog/p/9558678.html