0

这是问题所在。假设我有两个可变模块:

class DbModule extends Module {   bind[JdbcBackend#Database] toProvider
    inject[JdbcDriver].backend.Database.forURL(
      inject[String]("db.url"),
      inject[String]("db.username"),
      inject[String]("db.password"), null,
      inject[String]("db.driver")
    ) }

这是相应的配置:

资源/application.conf:

db {  url="postgres url"  username="db_user"  password="db_password"  driver="cc"  }

我在代码中的某处:

implicit val inj = TypesafeConfigInjector() :: new AppModule

然而,这个注入器给出了以下异常:

caldi.InjectException: No binding found with following identifiers:  
* TypeTagIdentifier(String)   * StringIdentifier(db.url)
4

1 回答 1

1

Scaldi 中的顺序很重要:绑定是从左到右解析的。

文档中所述,::运算符通过反转操作数来组成两个注入器。因此,在您的情况下,首先解决,因此它找不到注入的配置参数。AppModule

为了解决您的问题,请使用++操作员来保持您的注射器井然有序。

我希望这是有帮助的。

于 2017-02-27T16:46:17.030 回答