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

前端 未结 1 1197
独厮守ぢ
独厮守ぢ 2021-01-05 08:38

here\'s my code snippets.

here\'s my yml file:

productionServer:
  host: production-server.amazonaws.com
  publicIp: xx.xx.xx.xx
  privateIp: xx.xx.x         


        
相关标签:
1条回答
  • 2021-01-05 09:05

    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);
                }
            });
        }
    }
    
    0 讨论(0)
提交回复
热议问题