我有一个像这样的模块
public class JNDITransactionModule implements Module{
@Override
public void configure(Binder binder) {
binder.bind(TransactionManager.class)
.toProvider(
JndiIntegration.fromJndi(
TransactionManager.class,
"URI TO TRANSACTION MANAGER"))
.in(Scopes.SINGLETON);
}
}
嗯,我认为我的问题很简单,但是......我如何参数化“URI to TRANSACTION MANAGER”值?
我的意思是,像这样的事情
public class JNDITransactionModule implements Module{
@Override
public void configure(Binder binder) {
Properties props = getProperties("transaction.properties");
Names.bindProperties(binder, props);
binder.install(new TransactionModule());
binder.bind(TransactionManager.class)
.toProvider(
JndiIntegration.fromJndi(
TransactionManager.class,
"get @Named('transaction.jndi-uri')"))
.in(Scopes.SINGLETON);
}
}
和一个名为transaction.properties的配置文件,其中包含此
transaction.jndi-uri = URI TO TRANSACTION MANAGER
感谢!!!
答案 0 :(得分:1)
您应该能够使用单独的提供程序或 @Provides 方法。以下应该有效:
@Provides
@Singleton
TransactionManager provideTransactionManager(@Named("transaction.jndi-uri") String uri) {
return JndiIntegration.fromJndi(TransactionManager.class, uri).get();
}