SpringBoot admin

可以不需要注册中心,因为写这个的时候,maven的父pom 已经加了spring-cloud-starter-netflix-eureka-client

2.0版本的跟之前的版本配置文件不一样,写这个之前看了别人的教程,一直没行

服务端

新建个单独的项目(admin-server),端口号是10004

导包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>2.0.0</version>
</dependency>

<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.0.0</version>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>

启动类

1
2
3
4
5
6
7
8
9
10
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableAdminServer
public class AdminB2bApplication {

public static void main(String[] args) {
SpringApplication.run(AdminB2bApplication.class, args);
}
}

application.properties

1
2
3
4
5
6
7
8
spring.application.name=admin-b2b
server.port=10004

#配置eureka 的注册中心
eureka.client.serviceUrl.defaultZone: http://localhost:10002/eureka/

management.endpoints.web.exposure.include="*"
management.endpoint.health.show-details=always

客户端

客户端可以是注册中心,也可以是产品服务,用户服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.0.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>

application.properties

1
2
3
4
#配置eureka 的注册中心
eureka.client.serviceUrl.defaultZone: http://localhost:10002/eureka/

spring.boot.admin.client.url=http://localhost:10004

启动类

1
2
3
4
5
6
7
8
9
@SpringBootApplication
@EnableDiscoveryClient
public class DemoApplication {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}

}

导包的时候留意到@EnableDiscoveryClient @EnableEurekaClient 这两个注解,看了别人的,就懂了

https://blog.csdn.net/u012734441/article/details/78256256