1

私は最近、ActionBeans に Guice を導入しました。以前は、actionbean のデータ アクセス レイヤーの実装がハードコードされていました。

次のような統合テストがあります。

MockServletContext context = TestHelper.getServletContext();
MockRoundtrip trip = new MockRoundtrip(context, LoginActionBean.class);


trip.setParameter("authenticate", "Login");
trip.setParameter("username", "testuser2");
trip.setParameter("password", "testuser2pass");
trip.setParameter("targetUrl", "Activity.action?jobId=1");
trip.execute();

LoginActionBean bean = trip.getActionBean(LoginActionBean.class);

Guice を使用するようになったので、LoginActionBean に依存関係を注入する方法が見つかりません。実際に自分でインスタンス化したことがないからです。

このクラスに依存関係を注入するように guice に指示するにはどうすればよいですか?

4

1 に答える 1

1

web.xml (おそらくTestHelperクラスのgetServletContext()メソッド)にあるように、 MockServletContextを Guice 構成で構成する必要があります。

于 2011-06-10T19:09:47.417 に答える