我有一些关于 gwt-dispatch 和 guice 的问题。我正在使用 Guice 2.0、gwt-dispatch 1.1.0 快照、mvp4g 1.1.0 和 GIN 1.0
首先,我定义了简单的动作、结果和处理程序:
ListContactsAction.java
public class ListContactsAction implements Action<ListContactsResult>{
public ListContactsAction() {
}
}
ListContactsResult.java
public class ListContactsResult implements Result {
private List<Contact> contactList;
public ListContactsResult() {
}
public ListContactsResult(List<Contact> contactList) {
this.contactList = contactList;
}
public List<Contact> getContactList() {
return contactList;
}
}
ListContactsHandler.java
public class ListContactsHandler implements ActionHandler<ListContactsAction, ListContactsResult>{
@Inject
private SqlSessionFactory factory;
public Class<ListContactsAction> getActionType() {
return ListContactsAction.class;
}
public ListContactsResult execute(ListContactsAction a, ExecutionContext ec) throws DispatchException {
// some code using SqlSessionFactory and returning ListContactResult
// with list of contacts
}
public void rollback(ListContactsAction a, ListContactsResult r, ExecutionContext ec) throws DispatchException {
/* get action - no rollback needed */
}
}
在我的应用程序的以前版本中,它使用 rpc 服务而不是命令模式,我有一个提供SqlSessionFactory
注入的方法,如下所示:
@Provides
public SqlSessionFactory getSqlSessionFactory(){
// some code here
}
我在 gwt-dispatch 入门中读到,我必须在我的操作和它的处理程序之间提供绑定,它应该看起来像这样:
public class ContactModule extends ActionHandlerModule{
@Override
protected void configureHandlers() {
bindHandler(ListContactsAction.class, ListContactsHandler.class);
}
}
但是我在用 Guice 连接它时遇到问题,因为这个例子来自 gwt-dispatch 站点:
public class DispatchServletModule extends ServletModule {
@Override
public void configureServlets() {
serve( "/path/to/dispatch" ).with( DispatchServiceServlet.class );
}
}
不起作用,因为DispatchServiceServlet
包中没有。
我的问题是:
- 我应该如何编写 DispatchServletModule 以及如何实现(使用我应该提供的路径)
- 我应该在我的应用程序的 web.xml 文件中放入什么才能正确执行来自我的演示者的操作,该演示者具有 GIN 注入
DispatcherAsync
实现 - 我应该把我的
SqlSessionFactory
提供方法放在哪里(在哪个模块中)才能在我需要的地方注入 SqlSessionFactory - 我如何实例化注入器,以便可以在其他动作处理程序中正确使用它
我想这就是全部,我说清楚了。如果有些东西不够清楚,我会尝试更具体。