Spring Boot开发 之 应用监控Admin

本文的示例代码参考AdminServer & AdminClient

目录

  • AdminServer

  • AdminClient

AdminServer

spring init -b 1.5.6.RELEASE AdminServer
# cd AdminServer
vim pom.xml
# 省略了未修改代码
        
            de.codecentric
             spring-boot-admin-starter-server
            1.5.7
        
# 省略了未修改代码
vim src/main/java/com/example/AdminServer/DemoApplication.java
package com.example.AdminServer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import de.codecentric.boot.admin.config.EnableAdminServer;

@SpringBootApplication
@EnableAdminServer
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}
vim src/main/resources/application.properties
server.port=8088
  • 测试
mvn spring-boot:run

curl localhost:8080

maven安装 详细参考 SDKMAN

AdminClient

spring init -dweb -b 1.5.6.RELEASE AdminClient
# cd AdminClient
vim src/main/java/com/example/AdminClient/UserController.java
package com.example.AdminClient;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/users")
public class UserController {
    @GetMapping
    public String getUsers() {
        return "getUsers";
    }
}
  • 测试
mvn spring-boot:run

curl localhost:8080/users # 返回"getUsers"
vim pom.xml
# 省略了未修改代码
        
            de.codecentric
            spring-boot-admin-starter-client
            1.5.7
        
# 省略了未修改代码
vim src/main/resources/application.properties
spring.boot.admin.url=http://localhost:8088 
management.security.enabled=false
  • 测试
mvn spring-boot:run

curl localhost:8088

参考

  • Spring Boot Admin Reference Guide

  • SpringBoot Admin 使用指南

  • 1.系统监控使用springboot admin

你可能感兴趣的:(Spring Boot开发 之 应用监控Admin)