简体   繁体   中英

Spring boot actuator endpoints.enabled=false endpoints.health.enabled=true

I am working on enabling spring boot health check using actuator. Since our app is dependent on Spring 1.5.21, so I have to use actuator 1.5.21 release. I read some configurations on their online documentation shows that you can apply the following to only allow "/health" endpoint to expose.

By default, all endpoints except for shutdown are enabled. If you prefer to specifically “opt-in” endpoint enablement you can use the endpoints.enabled property. For example, the following will disable all endpoints except for info:

endpoints.enabled=false
endpoints.info.enabled=true

Since I need to disable all endpoints except "/health" endpoint, so I configured it in application.properties file like below. However, it is not working for me.

endpoints.enabled=false
endpoints.health.enabled=true

Here is the result:

http://localhost:8080/health

{"message":"This endpoint is disabled"}

Environments:

Spring boot: 1.5.21 release
JDK: 1.8
Application: web application

Any thoughts on this? Thanks in advance!

UPDATES:

After I started a new project using the same spring boot 1.5.21.RELEASE, below settings worked.

endpoints.enabled=false
endpoints.health.enabled=true
2020-03-29 19:29:15.541  INFO 9796 --- [  restartedMain] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal)

UPDATE on 3/30:

HOWEVER, when I used it with SDL Tridion 8.5, it stopped working. Any ideas?

        <dependency>
            <groupId>com.sdl.dxa</groupId>
            <artifactId>dxa-common-api</artifactId>
            <version>${dxaversion}</version>
        </dependency>
        <dependency>
            <groupId>com.sdl.dxa</groupId>
            <artifactId>dxa-common</artifactId>
            <version>${dxaversion}</version>
        </dependency>
        <dependency>
            <groupId>com.sdl.dxa</groupId>
            <artifactId>dxa-tridion-provider</artifactId>
            <version>${dxaversion}</version>
        </dependency>
        <dependency>
            <groupId>com.sdl.dxa.modules</groupId>
            <artifactId>dxa-module-core</artifactId>
            <version>${dxaversion}</version>
        </dependency>
endpoints.enabled=false
endpoints.health.enabled=true

Result:

http://localhost:8080/health

{"message":"This endpoint is disabled"}

No need to use disable. Use only below properties:

management.endpoints.web.exposure.include='health'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM