如图:按书中包含了actuator的依赖后,访问health节点失败。
一开始以为是版本不对,比对确认版本没问题。
分析服务启动时的log发现,下面标红的内容,加上这个path果然可以了。
2021-01-28 16:33:00.194 INFO 6540 --- [ main] croserviceSimpleConsumerMovieApplication : No active profile set, falling back to default profiles: default
2021-01-28 16:33:00.644 INFO 6540 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=df879624-8f35-3288-b32e-6d9ff4686b23
2021-01-28 16:33:00.785 INFO 6540 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8001 (http)
2021-01-28 16:33:00.794 INFO 6540 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-01-28 16:33:00.794 INFO 6540 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-01-28 16:33:00.892 INFO 6540 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-01-28 16:33:00.892 INFO 6540 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 682 ms
2021-01-28 16:33:01.100 INFO 6540 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-01-28 16:33:01.794 INFO 6540 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2021-01-28 16:33:01.865 INFO 6540 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8001 (http) with context path ''
2021-01-28 16:33:02.245 INFO 6540 --- [ main] croserviceSimpleConsumerMovieApplication : Started MicroserviceSimpleConsumerMovieApplication in 3.566 seconds (JVM running for 4.531)
2021-01-28 16:33:02.796 INFO 6540 --- [)-192.168.43.45] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-01-28 16:33:02.796 INFO 6540 --- [)-192.168.43.45] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2021-01-28 16:33:02.804 INFO 6540 --- [)-192.168.43.45] o.s.web.servlet.DispatcherServlet : Completed initialization in 8 ms
2021-01-28 16:33:21.770 ERROR 6540 --- [nio-8001-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8000/1": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect] with root cause