提问人:Paul Schimmer 提问时间:11/17/2023 最后编辑:Paul Schimmer 更新时间:11/17/2023 访问量:20
配置更改的 Guice 绑定
Guice bindings on config changes
问:
我正在使用 cfg4j 库来反映配置文件中更改的 bean 更改(自动重新加载/刷新)
public ConfigurationProvider getConfigurationProvider()
{
ConfigFilesProvider configFilesProvider = () -> Arrays.asList(Paths.get("session.properties"));
ConfigurationSource source = new FilesConfigurationSource(configFilesProvider);
Environment environment = new ImmutableEnvironment("/home/boss/");
ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(5, TimeUnit.SECONDS);
return new ConfigurationProviderBuilder()
.withConfigurationSource(source)
.withEnvironment(environment)
.withReloadStrategy(reloadStrategy)
.build();
}
...
//Binding on the class with Provider
getConfigurationProvider().bind("session-config",SessionConfig.class);
现在,现有应用程序也具有现有的 guice 绑定
import static io.airlift.configuration.ConfigBinder.configBinder;
...
Bootstrap app = new Bootstrap(
new ClientModule(),
binder -> {
configBinder(binder).bindConfig(SessionConfig.class);
});
我的问题是:如果我们添加额外的绑定 getConfigurationProvider().bind("sample-config",SessionConfig.class);
如何使用 SessionConfig 类的相同实例,或者将在两个绑定中使用该类的相同实例?
PS:我正在使用 airlift 框架进行 presto 中使用的 guice 绑定。
答: 暂无答案
评论