{"id":31970540,"url":"https://github.com/hubspot/dropwizard-guice","last_synced_at":"2025-10-14T19:16:13.730Z","repository":{"id":5721437,"uuid":"6932907","full_name":"HubSpot/dropwizard-guice","owner":"HubSpot","description":"Adds support for Guice to Dropwizard","archived":false,"fork":false,"pushed_at":"2020-02-05T20:49:32.000Z","size":224,"stargazers_count":266,"open_issues_count":21,"forks_count":94,"subscribers_count":192,"default_branch":"master","last_synced_at":"2025-07-20T08:46:22.880Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HubSpot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-30T03:34:41.000Z","updated_at":"2024-10-12T03:45:38.000Z","dependencies_parsed_at":"2022-08-31T08:41:58.181Z","dependency_job_id":null,"html_url":"https://github.com/HubSpot/dropwizard-guice","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/HubSpot/dropwizard-guice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fdropwizard-guice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fdropwizard-guice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fdropwizard-guice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fdropwizard-guice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HubSpot","download_url":"https://codeload.github.com/HubSpot/dropwizard-guice/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HubSpot%2Fdropwizard-guice/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020652,"owners_count":26086895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-14T19:16:04.661Z","updated_at":"2025-10-14T19:16:13.720Z","avatar_url":"https://github.com/HubSpot.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dropwizard-Guice\n\nA simple DropWizard extension for integrating Guice via a bundle. It optionally uses classpath \nscanning courtesy of the Reflections project to discover resources and more to install into \nthe dropwizard environment upon service start.\n\n### NOTE:\n\nThis library has been replaced by [dropwizard-guicier](https://github.com/HubSpot/dropwizard-guicier), so we don't recommend using it for new development.\n\n## Usage\n```xml\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.hubspot.dropwizard\u003c/groupId\u003e\n            \u003cartifactId\u003edropwizard-guice\u003c/artifactId\u003e\n            \u003cversion\u003e${current.version}\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n```\n\nA list of available versions can be found at https://github.com/HubSpot/dropwizard-guice/releases\n\nSimply install a new instance of the bundle during your service initialization\n```java\npublic class HelloWorldApplication extends Application\u003cHelloWorldConfiguration\u003e {\n\n  private GuiceBundle\u003cHelloWorldConfiguration\u003e guiceBundle;\n\n  public static void main(String[] args) throws Exception {\n    new HelloWorldApplication().run(args);\n  }\n\n  @Override\n  public void initialize(Bootstrap\u003cHelloWorldConfiguration\u003e bootstrap) {\n\n    guiceBundle = GuiceBundle.\u003cHelloWorldConfiguration\u003enewBuilder()\n      .addModule(new HelloWorldModule())\n      .setConfigClass(HelloWorldConfiguration.class)\n      .build();\n\n    bootstrap.addBundle(guiceBundle);\n  }\n\n  @Override\n  public String getName() {\n    return \"hello-world\";\n  }\n\n  @Override\n  public void run(HelloWorldConfiguration helloWorldConfiguration, Environment environment) throws Exception {\n    environment.jersey().register(HelloWorldResource.class);\n    environment.lifecycle().manage(guiceBundle.getInjector().getInstance(TemplateHealthCheck.class));\n  }\n}\n```\n\n## Auto Configuration\nYou can enable auto configuration via package scanning.\n```java\npublic class HelloWorldApplication extends Application\u003cHelloWorldConfiguration\u003e {\n\n  public static void main(String[] args) throws Exception {\n    new HelloWorldApplication().run(args);\n  }\n\n  @Override\n  public void initialize(Bootstrap\u003cHelloWorldConfiguration\u003e bootstrap) {\n\n    GuiceBundle\u003cHelloWorldConfiguration\u003e guiceBundle = GuiceBundle.\u003cHelloWorldConfiguration\u003enewBuilder()\n      .addModule(new HelloWorldModule())\n      .enableAutoConfig(getClass().getPackage().getName())\n      .setConfigClass(HelloWorldConfiguration.class)\n      .build();\n\n    bootstrap.addBundle(guiceBundle);\n  }\n\n  @Override\n  public String getName() {\n    return \"hello-world\";\n  }\n\n  @Override\n  public void run(HelloWorldConfiguration helloWorldConfiguration, Environment environment) throws Exception {\n    // now you don't need to add resources, tasks, healthchecks or providers\n    // you must have your health checks inherit from InjectableHealthCheck in order for them to be injected\n  }\n}\n```\n\nDropwizard `Task` requires a TaskName. Therefore when Auto Configuring a `Task`, you need to inject in the TaskName:\n```java\n    @Singleton\n    public class MyTask extends Task {\n\n        @Inject\n        protected MyTask(@Named(\"MyTaskName\") String name) {\n            super(name);\n        }\n\n        @Override\n        public void execute(ImmutableMultimap\u003cString, String\u003e immutableMultimap, PrintWriter printWriter) throws Exception {\n\n        }\n    }\n```\nAnd bind the TaskName in your module:\n\n    bindConstant().annotatedWith(Names.named(\"MyTaskName\")).to(\"my awesome task\");\n\nSee the test cases: `InjectedTask` and `TestModule` for more details.\n\n## Environment and Configuration\nIf you are having trouble accessing your Configuration or Environment inside a Guice Module, you could try using a provider.\n\n```java\npublic class HelloWorldModule extends AbstractModule {\n\n  @Override\n  protected void configure() {\n    // anything you'd like to configure\n  }\n\n  @Provides\n  public SomePool providesSomethingThatNeedsConfiguration(HelloWorldConfiguration configuration) {\n    return new SomePool(configuration.getPoolName());\n  }\n\n  @Provides\n  public SomeManager providesSomenthingThatNeedsEnvironment(Environment env) {\n    return new SomeManager(env.getSomethingFromHere()));\n  }\n}\n```\n\n## Injector Factory\nYou can also replace the default Guice `Injector` by implementing your own `InjectorFactory`. For example if you want \nto use [Governator](https://github.com/Netflix/governator), you can set the following InjectorFactory (using Java 8 Lambda)\nwhen initializing the GuiceBundle:\n\n```java\n@Override\npublic void initialize(Bootstrap\u003cHelloWorldConfiguration\u003e bootstrap) {\n\n  GuiceBundle\u003cHelloWorldConfiguration\u003e guiceBundle = GuiceBundle.\u003cHelloWorldConfiguration\u003enewBuilder()\n    .addModule(new HelloWorldModule())\n    .enableAutoConfig(getClass().getPackage().getName())\n    .setConfigClass(HelloWorldConfiguration.class)\n    .setInjectorFactory((stage, modules) -\u003e LifecycleInjector.builder()\n        .inStage(stage)\n        .withModules(modules)\n        .build()\n        .createInjector()))\n    .build();\n\n bootstrap.addBundle(guiceBundle);\n}\n```\n\n## Testing\nAs of Dropwizard 0.8.x, when writing Integration Tests using `DropwizardAppRule`, you need to reset\n[jersey2-guice](https://github.com/Squarespace/jersey2-guice) by running:\n\n    JerseyGuiceUtils.reset();\n\n## Examples\nPlease fork [an example project](https://github.com/eliast/dropwizard-guice-example) if you'd like to get going right away. \n\nYou may also find more updated and comprehensive examples in the [test cases](https://github.com/HubSpot/dropwizard-guice/tree/master/src/test).\n\nEnjoy!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhubspot%2Fdropwizard-guice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhubspot%2Fdropwizard-guice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhubspot%2Fdropwizard-guice/lists"}