Registering Dropwizard configuration with Jersey 2 (HK2) DI

倾然丶 夕夏残阳落幕 提交于 2019-12-10 12:22:45

问题


In my Dropwizard (1.2.4) application I'm having trouble injecting my Dropwizard configuration into classes that are instantiated by HK2. What's the best way to achieve this?


回答1:


Just bind the configuration instance.

@Override
public void run(final DummyConfiguration conf, Environment env) {
    env.jersey().register(new AbstractBinder() {
        @Override
        public void configure() {
            bind(conf).to(DummyConfiguration.class);
        }
    })
}

Now you can @Inject the DummyConfiguration anywhere you need it.



来源:https://stackoverflow.com/questions/50025855/registering-dropwizard-configuration-with-jersey-2-hk2-di

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!