Spring Eureka的使用入门

博客介绍了Eureka调度服务的搭建过程,包括Gradle依赖包、基础框架依赖配置核心代码、调度服务bulid.gralde、服务启动类、app.yml配置等内容,最后启动服务并访问指定地址完成注册中心启动。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值