HK2 Integration for Dropwizard

Adds support for Health Checks, LifeCycles, Metrics, and Tasks to be injected by HK2

Лицензия

Лицензия

Категории

Категории

DropWizard Контейнер Микросервисы HK2 Библиотеки уровня приложения Dependency Injection
Группа

Группа

co.wrisk.dropwizard
Идентификатор

Идентификатор

dropwizard-hk2
Последняя версия

Последняя версия

0.0.6
Дата

Дата

Тип

Тип

jar
Описание

Описание

HK2 Integration for Dropwizard
Adds support for Health Checks, LifeCycles, Metrics, and Tasks to be injected by HK2
Ссылка на сайт

Ссылка на сайт

https://github.com/WriskHQ/dropwizard-hk2
Система контроля версий

Система контроля версий

https://github.com/WriskHQ/dropwizard-hk2

Скачать dropwizard-hk2

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/co.wrisk.dropwizard/dropwizard-hk2/ -->
<dependency>
    <groupId>co.wrisk.dropwizard</groupId>
    <artifactId>dropwizard-hk2</artifactId>
    <version>0.0.6</version>
</dependency>
// https://jarcasting.com/artifacts/co.wrisk.dropwizard/dropwizard-hk2/
implementation 'co.wrisk.dropwizard:dropwizard-hk2:0.0.6'
// https://jarcasting.com/artifacts/co.wrisk.dropwizard/dropwizard-hk2/
implementation ("co.wrisk.dropwizard:dropwizard-hk2:0.0.6")
'co.wrisk.dropwizard:dropwizard-hk2:jar:0.0.6'
<dependency org="co.wrisk.dropwizard" name="dropwizard-hk2" rev="0.0.6">
  <artifact name="dropwizard-hk2" type="jar" />
</dependency>
@Grapes(
@Grab(group='co.wrisk.dropwizard', module='dropwizard-hk2', version='0.0.6')
)
libraryDependencies += "co.wrisk.dropwizard" % "dropwizard-hk2" % "0.0.6"
[co.wrisk.dropwizard/dropwizard-hk2 "0.0.6"]

Зависимости

runtime (1)

Идентификатор библиотеки Тип Версия
io.dropwizard : dropwizard-core jar 2.0.0-rc12

test (3)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12
io.dropwizard : dropwizard-testing jar 2.0.0-rc12
io.dropwizard : dropwizard-client jar 2.0.0-rc12

Модули Проекта

Данный проект не имеет модулей.

Dropwizard HK2 Integration

This bundle binds and integrates Dropwizard's HealthCheck, Metric, MetricSet, LifeCycle, LifeCycle.Listener, and Managed objects with HK2, allowing these components to be registered directly with Jersey and fully injected with any other services also known to HK2.

To use this bundle, add it to your application in the initialize method:

@Override
public void initialize(Bootstrap<YourConfig> bootstrap) {
    bootstrap.addBundle(new HK2Bundle<>());
}

Then, update your health checks, metrics, and managed components to use the custom Jersey component marker interfaces: InjectableHealthCheck, InjectableManaged, InjectableLifeCycle, InjectableLifeCycleListener, InjectableMetric, or InjectableMetricSet. These are necessary for Jersey to identify the components as a valid Jersey component, and just extend the Dropwizard interfaces of similar name. Here is an example health check:

@Named("TestHealthCheck")
public class TestInjectableHealthCheck extends InjectableHealthCheck {
    private final TestConfig config;

    @Inject
    public TestInjectableHealthCheck(TestConfig config) {
        this.config = config;
    }

    public TestConfig getConfig() {
        return config;
    }

    @Override
    protected Result check() throws Exception {
        return Result.healthy();
    }
}

Health checks and Metrics can also make use of the @Named() annotation to identify the name under which the component should be registered. If a name is not provided, a warning will be printed and a name generated in the format of ClassName.RandomUUID under which the component will be registered.

Lastly, register your components directly with Jersey:

@Override
public void run(TestConfig testConfig, Environment environment) throws Exception {
    environment.jersey().register(YourInjectableHealthCheck.class);
    environment.jersey().register(YourInjectableLifeCycle.class);
}

They will now be injected and registered properly with Dropwizard after HK2 and Jersey are initialized.

co.wrisk.dropwizard

Wrisk

Версии библиотеки

Версия
0.0.6
0.0.5