alex-shpak / Dropwizard Hk2bundle
Licence: mit
Dropwizard hk2 integration bundle
Stars: ✭ 12
Programming Languages
java
68154 projects - #9 most used programming language
Labels
Projects that are alternatives of or similar to Dropwizard Hk2bundle
metrics-agent
JVM agent based metrics with Prometheus and Dropwizard support (Java, Scala, Clojure, Kotlin, etc)
Stars: ✭ 25 (+108.33%)
Mutual labels: dropwizard
dropwizard-raven
Dropwizard integration for error logging to Sentry.
Stars: ✭ 20 (+66.67%)
Mutual labels: dropwizard
dropwizard-crypto
A Crytpographic Bundle for Dropwizard
Stars: ✭ 14 (+16.67%)
Mutual labels: dropwizard
verify-service-provider
👑 ☑️ The easiest way to connect to GOV.UK Verify
Stars: ✭ 15 (+25%)
Mutual labels: dropwizard
Node Measured
A Node metrics library for measuring and reporting application-level metrics, inspired by Coda Hale, Yammer Inc's Dropwizard Metrics Libraries
Stars: ✭ 500 (+4066.67%)
Mutual labels: dropwizard
helloworld-web
Hello World web application in 39 different ways in Java
Stars: ✭ 18 (+50%)
Mutual labels: dropwizard
dropwizard-auth-multitenancy-example
Sample code for my blog post
Stars: ✭ 15 (+25%)
Mutual labels: dropwizard
droptools
Addon bundle for Dropwizard to support jOOQ for database access
Stars: ✭ 78 (+550%)
Mutual labels: dropwizard
thunder
REST API application that manages user databases
Stars: ✭ 22 (+83.33%)
Mutual labels: dropwizard
Ratelimitj
A Java library for Rate-Limiting, providing extensible storage and application framework adaptors.
Stars: ✭ 362 (+2916.67%)
Mutual labels: dropwizard
dropwizard-orient-server
Embedded OrientDB server for dropwizard
Stars: ✭ 16 (+33.33%)
Mutual labels: dropwizard
Metrics Jvm Extras
A set of additional metrics complementing Dropwizards metrics-jvm.
Stars: ✭ 10 (-16.67%)
Mutual labels: dropwizard
Guardrail
Principled code generation from OpenAPI specifications
Stars: ✭ 396 (+3200%)
Mutual labels: dropwizard
kotlin-dropwizard
Getting Started with Dropwizard and Kotlin
Stars: ✭ 43 (+258.33%)
Mutual labels: dropwizard
Dropwizard hk2 Bundle
Dropwizard bundle for injection of managed objects, tasks etc using hk2 integration
Motivation
HK2 is default DI container in jersey, which is widely used in dropwizard, therefore it seems logical to use single DI container.
Features
- Registration and injection for:
- Healthchecks
- Managed objects
- Lifecycle listeners
- Tasks
- Commands
- Metrics
- Other bundles
- Jdbi DAOs injections
- Support for injections before Jersey initialisation
Usage
Grab latest version from JitPack
Gradle
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.github.alex-shpak:dropwizard-hk2bundle:0.8.1'
}
Code
Add bundle to your dropwizard application
ExampleAppBinder appBinder = new ExampleAppBinder();
HK2Bundle hk2Bundle = new HK2Bundle(appBinder);
bootstrap.addBundle(hk2Bundle);
Register DatabaseHealthCheck
in HK2 binder
public class ExampleAppBinder extends DropwizardBinder {
@Override
protected void configure() {
healthCheck(DatabaseHealthCheck.class);
}
}
DropwizardBinder
is convenience class that contains register()
method to register objects specific for dropwizard
So now DatabaseHealthCheck
get created and initialized by DI container
@Named("database") //Health check name. Class name will be used if not set
public class DatabaseHealthCheck extends HealthCheck {
@Inject
private Provider<Database> database;
@Override
protected Result check() throws Exception {
if(database.get().isConnected()) {
return Result.healthy();
}
return Result.unhealthy("Not connected");
}
}
JDBI DAO Injection
Considering you already have dropwizard-jdbi
module in dependencies, add JDBIBinder
to HK2Bundle
configuration.
Then you would be able to inject DAOs.
ExampleAppBinder appBinder = new ExampleAppBinder();
JDBIBinder jdbiBinder = new JDBIBinder<ExampleAppConfiguration>(configuration -> configuration.database)
// .setDBIFactory(JDBIFactory.class)
// .setSqlObjectFactory(SqlObjectFactory.class)
.register(ExampleDAO.class);
HK2Bundle hk2Bundle = new HK2Bundle(appBinder, jdbiBinder);
bootstrap.addBundle(hk2Bundle);
@Inject
private ExampleDAO exampleDAO;
Licence
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].