zoukankan      html  css  js  c++  java
  • 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

    注册中心启动完成;

  • 相关阅读:
    Query on The Trees(hdu 4010)
    背单词(bzoj 4567)
    P2819 图的m着色问题
    P1605 迷宫
    P1230 智力大冲浪
    P1082 同余方程
    P3372 【模板】线段树 1
    P2626 斐波那契数列(升级版)
    长生诀
    写给我第一个喜欢的男孩的歌
  • 原文地址:https://www.cnblogs.com/liangblog/p/9558678.html
Copyright © 2011-2022 走看看