一个应用程序中的Eureka Server和Spring Boot Admin

时间:2018-06-25 13:15:47

标签: spring-boot netflix-eureka spring-boot-admin

我尝试在一个应用程序中运行Eureka Server和Spring Boot Admin Server(SBA Docu说这是可能的)。 Eureka可以按预期工作,但Admin App仍然显示零个应用程序。

Spring Boot版本2.0.3, Spring Boot管理员版本2.0.1

Eureka和SBA服务器

@SpringBootApplication
@EnableEurekaServer
@EnableDiscoveryClient
@EnableAdminServer
class KotlintestApplication
fun main(args: Array<String>) {
    SpringApplication.run(KotlintestApplication::class.java, *args)
}

服务器bootstrap.yml

spring:
      application:
        name: server

服务器application.yml

spring:
  boot:
   admin:
     context-path: /admin

eureka:
  instance:
    leaseRenewalIntervalInSeconds: 10
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://localhost:8080/eureka

客户

@EnableDiscoveryClient
@SpringBootApplication
class KotlintestApplication

fun main(args: Array<String>) {
    SpringApplication.run(KotlintestApplication::class.java, *args)
}

@Configuration
class SecurityPermitAllConfig : WebSecurityConfigurerAdapter() {
    @Throws(Exception::class)
    override fun configure(http: HttpSecurity) {
        http.authorizeRequests().anyRequest().permitAll()
                .and().csrf().disable()
    }
}

客户端bootstrap.yml

 spring:
      application:
        name: client
 server:
    port: 0

客户端application.yml

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS

eureka:
  instance:
    hostname: localhost
    health-check-url-path: /actuator/health
    status-page-url-path: /actuator/info
  client:
    serviceUrl:
      defaultZone: http://127.0.0.1:8080/eureka/

1 个答案:

答案 0 :(得分:3)

自己找到答案

从服务器application.yaml中删除fetchRegistry: false。 服务器必须获取注册表才能查看客户端...

Btw:如果要在同一主机上使用随机端口运行多个实例,则应设置instanceId。否则,实例之间的SBA不能相同。

eureka:
  instance:
    instanceId : client-${random.uuid}