spring boot actuator endpoints not activated

javapedia.net :

I am learning Spring boot Actuator, notice that spring boot actuator not getting activated. I am following the documentation [spring docs][1], so adding the maven dependency as mentioned.

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

My 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>net.javapedia</groupId>
    <artifactId>spring-scheduling</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-scheduling</name>
    <description>Spring scheduling example</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


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

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

</project>

My Spring application:

package net.javapedia.springscheduling;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class SpringSchedulingApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringSchedulingApplication.class, args);
    }

}

application.properties

management.endpoints.enabled-by-default=true

Console output:

2020-03-28 22:05:31.184  INFO 63611 --- [           main] n.j.s.SpringSchedulingApplication        : Starting SpringSchedulingApplication on localhost with PID 63611 (/Users/admin/IdeaProjects/spring-scheduling/target/classes started by admin in /Users/admin/IdeaProjects/spring-scheduling)
2020-03-28 22:05:31.189  INFO 63611 --- [           main] n.j.s.SpringSchedulingApplication        : No active profile set, falling back to default profiles: default
2020-03-28 22:05:33.279  INFO 63611 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'taskScheduler'
Running fixedRate Task, Thread name: scheduling-1
Running scheduled Task, iteration :1 Thread name: scheduling-1
2020-03-28 22:05:33.342  INFO 63611 --- [           main] n.j.s.SpringSchedulingApplication        : Started SpringSchedulingApplication in 2.791 seconds (JVM running for 4.108)

I am trying to access the actuator health endpoint at http://localhost:8080/actuator/health but no luck.

  [1]: http://%20https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-enabling
rxn1d :

Please add the following to your pom.xml:

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

I've copied your setup and it really didn't work initially. But it worked out after I've added spring-boot-starter-web. It seems that you have to have web dependencies to spin up any controller, not only app-specific but even actuator's.

App log:

2020-03-29 10:27:36.934  INFO 29814 --- [           main] com.example.SpringSchedulingApplication  : Starting SpringSchedulingApplication on Users-MacBook-Pro-4.local with PID 29814 (/Users/user/projects/test/target/classes started by user in /Users/user/projects/test)
2020-03-29 10:27:36.936  INFO 29814 --- [           main] com.example.SpringSchedulingApplication  : No active profile set, falling back to default profiles: default
2020-03-29 10:27:37.623  INFO 29814 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (HTTP)
2020-03-29 10:27:37.628  INFO 29814 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-03-29 10:27:37.628  INFO 29814 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-03-29 10:27:37.677  INFO 29814 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-03-29 10:27:37.677  INFO 29814 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 715 ms
2020-03-29 10:27:37.890  INFO 29814 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-29 10:27:38.012  INFO 29814 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'taskScheduler'
2020-03-29 10:27:38.015  INFO 29814 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
2020-03-29 10:27:38.056  INFO 29814 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-03-29 10:27:38.058  INFO 29814 --- [           main] com.example.SpringSchedulingApplication  : Started SpringSchedulingApplication in 1.283 seconds (JVM running for 1.797)
2020-03-29 10:27:38.413  INFO 29814 --- [on(1)-127.0.0.1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-03-29 10:27:38.413  INFO 29814 --- [on(1)-127.0.0.1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2020-03-29 10:27:38.418  INFO 29814 --- [on(1)-127.0.0.1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 5 ms

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=360203&siteId=1