簡體   English   中英

Spring Boot Actuator 不工作並且 application.properties 在 STS 中是未知的

[英]Spring Boot Actuator not working and application.properties are Unknown in STS

嘗試使用Web執行器依賴項測試Spring Initializr Starter,但執行器端點未啟用。

我期待在Spring Boot Actuator: Production-ready features 的每個文檔的日志中映射 /actuator/health

新的 Spring Initializr SpringBoot Web+Actuator

我在application.properties 中嘗試了各種屬性:

management.security.enabled=false 

management.endpoints.web.exposure.include=*

management.endpoints.web.expose=*

在 STS 中,所有三行都帶有黃色下划線,並帶有指示未知屬性的消息。

我沒有碰Spring Initializr生成的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.geodepe.test</groupId>
<artifactId>health1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>health1</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

我希望這能工作,這里是沒有執行器映射的部分日志:

2018-08-06 21:06:14.235  INFO 52763 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 689 ms
2018-08-06 21:06:14.276  INFO 52763 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-08-06 21:06:14.279  INFO 52763 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-08-06 21:06:14.279  INFO 52763 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-08-06 21:06:14.280  INFO 52763 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-08-06 21:06:14.280  INFO 52763 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-08-06 21:06:14.355  INFO 52763 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-06 21:06:14.484  INFO 52763 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@a4102b8: startup date [Mon Aug 06 21:06:13 CDT 2018]; root of context hierarchy
2018-08-06 21:06:14.517  INFO 52763 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-08-06 21:06:14.517  INFO 52763 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-08-06 21:06:14.532  INFO 52763 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-06 21:06:14.532  INFO 52763 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-08-06 21:06:14.618  INFO 52763 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-08-06 21:06:14.653  INFO 52763 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-08-06 21:06:14.656  INFO 52763 --- [           main] c.f.test.health1.Health1Application      : Started Health1Application in 1.347 seconds (JVM running for 1.741)

卷曲測試:

curl 'http://localhost:8080/actuator/health' -i -X GET
HTTP/1.1 404 
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 07 Aug 2018 03:09:02 GMT

{"timestamp":"2018-08-07T03:09:02.385+0000","status":404,"error":"Not Found","message":"No message available","path":"/actuator/health"}

任何機構都可以告訴我我缺少什么以及為什么 STS 無法識別這些屬性嗎?

這與“SpringBoot 2.0.1 中未提供執行器/刷新”不重復。 下面的解決方案表明這是一個 JAR 損壞問題。

運行后

mvn clean install 

盡管 IDE 一直在運行而不告訴我有關它們的信息(奇怪),但我還是看到了多個錯誤。

 [INFO] BUILD FAILURE
 [INFO] ------------------------------------------------------------------------
 [INFO] Total time: 1.774 s
 [INFO] Finished at: 2018-08-07T17:13:29-05:00
 [INFO] ------------------------------------------------------------------------
 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project health1: Compilation failure: Compilation failure: 
 [ERROR] error reading /Users/xxx/.m2/repository/org/springframework/boot/spring-boot-actuator-autoconfigure/2.0.4.RELEASE/spring-boot-actuator-autoconfigure-2.0.4.RELEASE.jar; ZipFile invalid LOC header (bad signature)
 [ERROR] error reading /Users/xxx/.m2/repository/org/springframework/boot/spring-boot-actuator/2.0.4.RELEASE/spring-boot-actuator-2.0.4.RELEASE.jar; ZipFile invalid LOC header (bad signature)
 [ERROR] error reading /Users/xxx/.m2/repository/io/micrometer/micrometer-core/1.0.6/micrometer-core-1.0.6.jar; ZipFile invalid LOC header (bad signature)
 [ERROR] /Users/georgedeprez/Documents/workspace-sts/health1/src/main/java/com/finantica/test/health1/Health1Application.java:[1,1] cannot access com.finantica.test.health1
 [ERROR]   invalid code lengths set
 [ERROR] -> [Help 1]
 org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal    org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project health1: Compilation failure

刪除罐子后:

rm /Users/xxx/.m2/repository/org/springframework/boot/spring-boot-actuator-autoconfigure/2.0.4.RELEASE/spring-boot-actuator-autoconfigure-2.0.4.RELEASE.jar
rm /Users/xxx/.m2/repository/org/springframework/boot/spring-boot-actuator/2.0.4.RELEASE/spring-boot-actuator-2.0.4.RELEASE.jar
rm /Users/xxx/.m2/repository/io/micrometer/micrometer-core/1.0.6/micrometer-core-1.0.6.jar

其次是

mvn spring-boot:run

強制重新下載。

現在我看到指示暴露端點的日志:

在此處輸入圖片說明

/actuator/health 現在產生:

在此處輸入圖片說明

我的情況是我必須添加我的自定義 HealthIndicator:

 @Component
 public class HealthIndicator implements ReactiveHealthIndicator {

     @Override
     public Mono<Health> health() {
       return checkDownstreamServiceHealth().onErrorResume(
          ex -> Mono.just(new Health.Builder().down(ex).build())
       );
     }

     private Mono<Health> checkDownstreamServiceHealth() {
       return Mono.just(new Health.Builder().up().build());
     }
 }

我使用彈簧靴執行器 2.2.3。 來自https://www.baeldung.com/spring-boot-actuators

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM