无法连接到端口 9001 上的 MBean 服务器 - ApplicationReadyEvent 之后进行运行状况检查

问题描述 投票:0回答:1

在为应用程序添加以下运行状况指标和预热事件后,我收到错误

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.3.2.RELEASE:start (pre-integration-test) Could not figure out if the application has started: Failed to connect to MBean server at port 9001: Could not invoke shutdown operation: Connection refused to host: 127.0.0.1; nested exception is: [ERROR] java.net.ConnectException: Connection refused (Connection refused)
。不知道为什么我会收到此错误。请指教

ApplicationReadyEvent之后如何进行执行器健康检查?或者不需要ApplicationReadyEvent?

@Component
public class Warmup implements HealthIndicator, ApplicationListener<ApplicationReadyEvent> {

    private boolean warmUpOver;

    @Autowired
    public Warmup(){
       
    }

    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
        warmUpMethod();
    }

    public void warmUpMethod(){
        //Once the method is over 
        warmUpOver = true;
    }

    @Override
    public Health health() {
        if(warmUpOver){
            final Health.Builder builder = Health.up();
            return builder.build();
        } else {
            final Health.Builder builder = Health.unknown();
            return builder.build();
        }
    }
}
java spring-boot spring-boot-actuator mbeans spring-boot-maven-plugin
1个回答
0
投票

当我们尝试运行应用程序两次时,这可能是一个问题,请检查您的应用程序是否已经在运行

© www.soinside.com 2019 - 2024. All rights reserved.