1

Trying to test Spring Initializr Starter with Web and Actuator dependencies, but actuator endpoints are not becoming enabled.

I am expecting mapping /actuator/health in logs per documentation at Spring Boot Actuator: Production-ready features

New Spring Initializr SpringBoot Web+Actuator

I tried various properties, in application.properties:

management.security.enabled=false 

management.endpoints.web.exposure.include=*

management.endpoints.web.expose=*

In STS, all three lines are yellow underlined with message indicating unknown property.

I did not touch the pom.xml file generated by Spring Initializr:

<?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>

I would expect this to work, here is partial log without actuator mappings:

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 test:

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"}

Can any body tell me what I am missing and why STS does not recognize the properties?

This is not a duplicate to "actuator /refresh is not being provided in SpringBoot 2.0.1". The solution below shows that it was a JAR corruption problem.

Geodepe
  • 147
  • 1
  • 10
  • you can not disable spring security from properties – GolamMazid Sajib Aug 07 '18 at 03:15
  • https://stackoverflow.com/questions/51535967/how-to-disable-security-in-spring-boot-2/51536146#51536146 – GolamMazid Sajib Aug 07 '18 at 03:15
  • Adding `spring-boot-starter-actuator` dependency is enough, which you already have. You shouldn't need to have those properties. Have you tried removing those properties in application.properties? – Kartik Aug 07 '18 at 04:41
  • 1
    Also try rebuilding the project and re-running. Sometimes if the jar is not completely download and you start the app, the actuator endpoints are not available. – Kartik Aug 07 '18 at 04:46
  • Possible duplicate of [actuator /refresh is not being provided in SpringBoot 2.0.1](https://stackoverflow.com/questions/50114501/actuator-refresh-is-not-being-provided-in-springboot-2-0-1) – Mehraj Malik Aug 07 '18 at 05:19
  • @sajib I don't think security is the problem. I tried the WebSecurityConfig you referenced, but that added dependencies and did not solve the problem. – Geodepe Aug 07 '18 at 22:06
  • @Kartik checking the jar were corrupted. – Geodepe Aug 07 '18 at 22:24
  • @Mehraj Malik Thanks for the suggestion, but it was something else. – Geodepe Aug 07 '18 at 23:02

2 Answers2

2

After running

mvn clean install 

I saw multiple errors even though IDE kept running without telling me about them (strange).

 [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

After deleting the jars:

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

Followed by

mvn spring-boot:run

to force re-download.

Now I see logs indicating exposed endpoints:

enter image description here

/actuator/health now produces:

enter image description here

Geodepe
  • 147
  • 1
  • 10
0

I my case I had to add my custom 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());
     }
 }

I use spring boot actuator 2.2.3. From https://www.baeldung.com/spring-boot-actuators

James Parson
  • 65
  • 1
  • 11