当前位置: 首页 > 知识库问答 >
问题:

Spring引导执行器endpoint未激活

锺离浩慨
2023-03-14
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
</dependencies>
<?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>
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);
    }

}
management.endpoints.enabled-by-default=true

控制台输出:

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)

我试图访问http://localhost:8080/acturet/health的执行器健康endpoint,但没有成功。

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

共有1个答案

陶俊晤
2023-03-14

请将以下内容添加到pom.xml中:

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

我已经复制了你的设置,它真的不起作用一开始。但是在我添加了spring-boot-starter-web之后,它就成功了。看来,您必须有Web依赖关系才能升级任何控制器,不仅是特定于应用程序的控制器,甚至是acture的控制器。

应用程序日志:

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
 类似资料:
  • {“Status”:“Down”} 我需要做什么才能显示自定义健康状况指示器?

  • Spring Boot执行器的两个版本(1.2.5和1.3.0)在HealthMvcEndpoint,isUnrestricted()方法(&&and)中的实现存在差异。我明白这是为了保留这些限制 http://docs.spring.io/spring-boot/docs/current-snapshot/reference/htmlsingle/#production-ready-health

  • 我有一个使用spring Boot1.4.2和CXF JAXR的项目设置。我想把Spring引导执行器添加到项目中。这是我添加到项目中的配置。 在此之后创建一个WAR文件,然后将其部署在外部tomcat服务器中。但是当我访问健康URL localhost:8080/management/health时,它给出的是404 HTTP代码。服务器正常启动,我可以看到包含以下详细信息的日志: 运行状况配置

  • 我第一次使用Spring Boot应用程序时,执行器是不安全的,所以很容易通过/acture/shutdownendpoint远程关闭。最近,我已经使用Spring安全保护了我的执行器,它已经起作用了。现在我需要提供http基本凭据来访问endpoint,但现在对/acture/shutdownendpoint的curl调用失败,出现禁止错误。我一定是配置不正确的地方。 我的卷曲命令: 我的配置:

  • 但我想要一些我可以调用从AWS弹性负载均衡器/自动缩放组。默认情况下,如果一个实例未通过健康检查,ELB/ASG将终止它并用一个新的实例替换它。问题是一些健康检查,如DataSourceHealthIndicator,会在数据库关闭时向下报告,但我的应用程序实例在其他方面是完全健康的。如果我使用默认行为,AWS将抛出完全正常的实例,直到数据库重新启动,这将导致我的账单增加。 我可以去掉DataSo