在Jersey 2(HK2)DI上注册Dropwizard配置 [英] Registering Dropwizard configuration with Jersey 2 (HK2) DI

查看:181
本文介绍了在Jersey 2(HK2)DI上注册Dropwizard配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Dropwizard(1.2.4)应用程序中,我无法将我的Dropwizard配置注入到HK2实例化的类中.实现此目标的最佳方法是什么?

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?

推荐答案

只需绑定配置实例.

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

现在,您可以在需要的任何地方@Inject DummyConfiguration.

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

这篇关于在Jersey 2(HK2)DI上注册Dropwizard配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆