本文项目为 springcloud 2.X ,其通过Eureka来注册/发现
官方相关地址:
- github https://github.com/codecentric/spring-boot-admin
- 文档 https://github.com/codecentric/spring-boot-admin/blob/master/spring-boot-admin-docs/src/main/asciidoc/index.adoc
- 示例 https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples
创建简单Eureka Server
详细创建过程请各位童鞋自行查找,这里只做一些配置的简单说明
版本:spring-boot 2.1.0 springcloud Finchley.SR2
- pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
- Eureka Server 启动类
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
- application.yml
eureka:
instance:
hostname: localhost
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
client:
fetch-registry: false
register-with-eureka: false
service-url:
defaultZone: http://localhost:9010/eureka/
创建Admin Server
- pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
- Eureka Client启动类
@SpringBootApplication
@EnableEurekaClient
@EnableAdminServer
public class EurekaClientApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientApplication .class, args);
}
}
- application.yml
spring:
application:
name: eurekaClient
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
eureka:
client:
service-url:
defaultZone: http://10.0.10.135:9010/eureka/
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
其它配置
info:
version: "1.0"
service: ${spring.application.name}
port: ${server.port}