1.集成akim-cloud-monitor
2.网关引用依赖
<!--actuator 监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId> <!-- 实现 Spring Boot Admin Server 服务端 -->
</dependency>
3.网关启动Application添加注解
@EnableAdminServer
例:
@SpringBootApplication
@EnableAdminServer
public class GatewayServerApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayServerApplication.class, args);
}
}
4.增加application.yaml配置
这里需要看profiles使用的是什么环境,这里使用的local,所以配置文件为application-local.yaml,如果不配置,则会与swagger冲突,导致通过网关访问swagger报404,主要是更改管理上下文(https://cloud.tencent.com/developer/ask/sof/1573870):
spring:
boot:
admin:
client:
url: http://127.0.0.1:${server.port}/${spring.boot.admin.context-path} # 设置 Spring Boot Admin Server 地址
instance:
service-host-type: IP
context-path: /admin
4.访问网关地址
例:http://localhost:8080
文章评论