1
注入されたオブジェクトを持つコントローラをテストするには、Playのドキュメントのthis exampleに従っています。例を複製しましたが、Webページを呼び出す際にエラーが発生します。Scalaの注入コントローラのテスト
test.Componentの実装がバインドされていません。
エラーは私がbinding
メソッドを呼び出すのではないようですが、これを修正するにはどうすればよいですか?
これは私のコードです:
package test
import play.api.mvc._
import javax.inject.Inject
import play.api.{ Environment, Configuration }
import play.api.inject.Module
trait Component {
def hello: String
}
class DefaultComponent extends Component {
def hello = "default"
}
class MockComponent extends Component {
def hello = "mock"
}
class ComponentModule extends Module {
def bindings(env: Environment, conf: Configuration) = Seq(
bind[Component].to[DefaultComponent]
)
}
class Application @Inject() (component: Component) extends Controller {
def index() = Action {
Ok(component.hello)
}
}
がどのようにこのコードを実行しているapplication.confに追加しますか?あなたは 'ComponentModule'がプレーで認識されていることをどうやって確認していますか? – rethab
私は 'GET/testapp test.Application.index'ルートにエントリを持っています。私は 'ComponentModule'をPlayによって認識させる方法を知らない、それはPlayの例で欠落している部分です。質問のリンクを見てください。 – ps0604