Eureka服务注册中心

gradle配置
  • build.gradle
  1. dependencyManagement {
  2. imports {
  3. mavenBom ('org.springframework.cloud:spring-cloud-dependencies:Camden.SR3')
  4. }
  5. }
  6. dependencies {
  7. compile ('org.springframework.cloud:spring-cloud-starter-eureka-server')
  8. testCompile('org.springframework.boot:spring-boot-starter-test')
  9. }

启动代码
  • 只需添加@EnableEurekaServer注解即可配置一个工程为Eureka服务端
  1. @EnableEurekaServer
  2. @SpringBootApplication
  3. public class XyEurekaApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(XyEurekaApplication.class, args);
  6. }
  7. }

application配置
  • 需要配置程序自身不作为客户端注册服务
  • application.yml
server:
  port: 10000
eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

登录Eureka管理端