在项目中使用SpringBootAdmin分为两部分: 服务端与客户端。客户端通过http的方式向服务端提供自生的运行状况
<spring.boot.admin.version>2.1.6</spring.boot.admin.version>
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>${spring.boot.admin.version}</version> </dependency> 复制代码
@EnableAdminServer
server: port: 8080 复制代码
如果有报错:
2019-11-02 09:50:14.924 ERROR 55391 --- [nio-8080-exec-2] o.a.catalina.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] at org.apache.coyote.AbstractProcessor.action(AbstractProcessor.java:512) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.Request.action(Request.java:430) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.AsyncContextImpl.setErrorState(AsyncContextImpl.java:396) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:239) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.AbstractProcessor.dispatch(AbstractProcessor.java:241) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53) [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] 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(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.16.jar:9.0.16] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_191] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_191] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.16.jar:9.0.16] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191] 复制代码
<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> 复制代码
完整项目源代码在 github.com/FutaoSmile/…
<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> 复制代码
spring: boot: admin: client: url: http://localhost:8080 management: endpoints: web: exposure: include: "*" endpoint: health: show-details: always 复制代码
http://localhost:8080
@RestControllerAdvice
则约束一下包路径 @RestControllerAdvice("com.west.lake.blog.controller")
请求日志与请求耗时监控
缓存管理器