Created
March 6, 2016 18:53
-
-
Save derekbassett/712698cd6424e5ff04da to your computer and use it in GitHub Desktop.
An example of using Jersey's dependency injection framework in a DropWizard application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.derekbassett.exampledropwizard | |
import com.mongodb.MongoClient; | |
import io.dropwizard.Application; | |
import io.dropwizard.setup.Bootstrap; | |
import io.dropwizard.setup.Environment; | |
import org.glassfish.hk2.utilities.binding.AbstractBinder; | |
public class ExampleDropwizardApplication extends Application<ExampleDropwizardApplicationConfiguration> { | |
public static void main(final String[] args) throws Exception { | |
new ExampleDropwizardApplication().run(args); | |
} | |
@Override | |
public void initialize(final Bootstrap<ExampleDropwizardApplicationConfiguration> bootstrap) { | |
} | |
@Override | |
public void run(final ExampleDropwizardApplicationConfiguration configuration, final Environment environment) throws Exception { | |
final MongoClient mongoClient = configuration.getMongoClientFactory().buildClient(environment, "mongo"); | |
environment.jersey().register(new AbstractBinder() { | |
@Override | |
protected void configure() { | |
bind(configuration).to(ExampleDropwizardApplicationConfiguration.class); | |
bind(mongoClient).to(mongoClient); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment