• Github address: github.com/codecentric…
  • The document address: codecentric. Making. IO/spring – the boot…

Using SpringBootAdmin in a project has two parts: the server side and the client side. The client provides its own health to the server over HTTP

  • Version:< spring boot. Admin. Version > 2.1.6 < / spring. The boot. Admin. Version >

1. Build a server project

  • Server side dependency
             <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-starter-server</artifactId>
                <version>${spring.boot.admin.version}</version>
            </dependency>
Copy the code
  • Start the markup annotation on the class@EnableAdminServer
  • Set port
server:
  port: 8080
Copy the code
  • Start to

If there is an error:

The 2019-11-02 09:50:14. ERROR 924-55391 [nio - 8080 - exec - 2] O.A.C atalina. Connector. CoyoteAdapter: Exception while processing an asynchronous request java.lang.IllegalStateException: Calling [asyncError()] is not valid for a request with Async state [MUST_DISPATCH] at Org. Apache. Coyote. AsyncStateMachine. AsyncError (AsyncStateMachine. Java: 440) ~ [tomcat embed - core - 9.0.16. Jar: 9.0.16] the at Org. Apache. Coyote. AbstractProcessor. Action (AbstractProcessor. Java: 512) [tomcat embed - core - 9.0.16. Jar: 9.0.16] the at Org. Apache. Coyote. Request. The action (Request. Java: 430) ~ [tomcat embed - core - 9.0.16. Jar: 9.0.16] the at org.apache.catalina.core.AsyncContextImpl.setErrorState(AsyncContextImpl.java:396) ~ [tomcat - embed - core - 9.0.16. Jar: 9.0.16] the at Org. Apache. Catalina. Connector. CoyoteAdapter. AsyncDispatch (CoyoteAdapter. Java: 239) ~ [tomcat embed - core - 9.0.16. Jar: 9.0.16] The at org. Apache. Coyote. AbstractProcessor. Dispatch (AbstractProcessor. Java: 241) [tomcat embed - core - 9.0.16. Jar: 9.0.16] the at Org. Apache. Coyote. AbstractProcessorLight. Process (53) AbstractProcessorLight. Java: [tomcat embed - core - 9.0.16. Jar: 9.0.16] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) [tomcat - embed - core - 9.0.16. Jar: 9.0.16] the at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) [tomcat - embed - core - 9.0.16. Jar: 9.0.16] at org.apache.tomcat.util.net.SocketProcessorBase.run (49) SocketProcessorBase. Java: [tomcat - embed - core - 9.0.16. Jar: 9.0.16] the at Java. Util. Concurrent. ThreadPoolExecutor. RunWorker (ThreadPoolExecutor. Java: 1149) [na: 1.8.0 comes with _191] the at Java. Util. Concurrent. ThreadPoolExecutor $Worker. The run (ThreadPoolExecutor. Java: 624) [na: 1.8.0 comes with _191] the at Org, apache tomcat. Util. Threads. TaskThread $WrappingRunnable. Run (TaskThread. Java: 61) [tomcat embed - core - 9.0.16. Jar: 9.0.16] The at Java. Lang. Thread. The run (Thread. Java: 748) [na: 1.8.0 comes with _191]Copy the code
  • Change Tomcat to Jetty
 <dependencies>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
    </dependencies>
Copy the code

Complete project source code at github.com/FutaoSmile/…


2. Client – Services that need to be monitored

  • Add client dependencies
       <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
        </dependency>
        <! -- > https://codecentric.github.io/spring-boot-admin/2.1.6/#getting-started--
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>2.1.6</version>
        </dependency>
Copy the code
  • Configure the address of the SpringBootAdmin server
spring:
    boot:
        admin:
          client:
            url: http://localhost:8080

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always
Copy the code
  • Start the SpringBoot client project
  • Address to access server configuration:http://localhost:8080
  • If you don’t have data, do something like this

    This is because your SpringBoot project encapsulates the data returned by the monitoring endpoint, as can be seen from the data structure returned by Info.

  • The solution is not to let SpringBoot encapsulate the data returned by the monitoring endpoint
  • Student: If you use theta@RestControllerAdviceThen constrain the package path@RestControllerAdvice("com.west.lake.blog.controller")

  • Monitor request logs and request time

  • Cache manager