问题
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