在我的 DropWizard (v0.7.0) 应用程序中,我有一个像这样的 DummyHealthCheck
:
public class DummyHealthCheck extends HealthCheck {
@Override
protected Result check() throws Exception {
return Result.healthy();
}
}
然后在我的主要 Application
impl 中:
public class MyApplication extends Application<MyConfiguration> {
@Override
public void run(MyConfiguration configuration, Environment environment)
throws Exception {
environment.jersey().register(new DummyHealthCheck());
}
}
当我启动服务器时,它成功启动(没有异常/错误),但是我收到以下消息:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! THIS APPLICATION HAS NO HEALTHCHECKS. THIS MEANS YOU WILL NEVER KNOW !
! IF IT DIES IN PRODUCTION, WHICH MEANS YOU WILL NEVER KNOW IF YOU'RE !
! LETTING YOUR USERS DOWN. YOU SHOULD ADD A HEALTHCHECK FOR EACH OF YOUR !
! APPLICATION'S DEPENDENCIES WHICH FULLY (BUT LIGHTLY) TESTS IT. !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
但是当我访问 http://localhost:8081/healthcheck
时,我看到:
{"deadlocks":{"healthy":true}}
- 这是怎么回事?如何注册我的健康检查?
- 此外,我已将 DropWizard 配置为在端口 8443 上使用 SSL(自签名);我已经验证这适用于我的正常端点。然而,令我惊讶的是,我的管理应用仍然通过 HTTP 在 8081 上公开。我如何为 HTTPS 配置它?
最佳答案
问题一:
您无需向 Jersey 注册它,因为健康检查是特定于 DropWizard 的。他们应该注册如下
environment.healthChecks().register("dummy", new DummyHealthCheck());
解释为 here .如果它是如上注册的,您会看到
{"deadlocks":{"healthy":true}, "dummy":{"healthy":true}}
问题2:
我假设你已经做过类似的事情
server:
applicationConnectors:
- type: https
port: 8443
keyStorePath: example.keystore
keyStorePassword: example
validateCerts: false
在您的 yaml 中,如 here 所示.那只是为了申请。您还需要配置管理员
server:
applicationConnectors:
- ...
adminConnectors:
- type: https
port: 8444 // should a different port from the application
keyStorePath: example.keystore
keyStorePassword: example
validateCerts: false
关于java - DropWizard 没有注册我的健康检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27431327/