how to get my configuration values in yml - using dropwizard (microservice) Jersey D.I @Injection?

こ雲淡風輕ζ 提交于 2019-11-30 20:23:34

The problem is, with this configuration

bind(MyConfiguration.class).to(MyConfiguration.class);

HK2 will create a new instance of the MyConfiguration. It will not be the same instance populated by DW. What you can do though, is use the instance created by DW, by simply binding that same instance in your HK2 configuration

public class MyApplication extends Application<MyConfiguration> {

    @Override
    public void run(final MyConfiguration config, Environment env) {
        env.jersey().register(new AbstractBinder() {
            @Override
            protected void configure() {
                bind(config).to(MyConfiguration.class);
            }
        });
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!