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

您需要使用 Guice 配置来配置MockServletContext,就像您在 web.xml 中所做的那样(可能在您的TestHelpergetServletContext()方法中)。

于 2011-06-10T19:09:47.417 回答