我得到一个奇怪的错误,我不能通过使用辅助注射:
[DEBUG] [project] - Rebinding com.gwtplatform.mvp.client.DesktopGinjector
[DEBUG] [project] - Invoking generator com.google.gwt.inject.rebind.GinjectorGenerator
[ERROR] [project] - Factory com.jorsek.editor.gin.EditorClientFactory could not be created
[ERROR] [project] - Error injecting com.jorsek.editor.gin.EditorClientFactory: Unable to create or inherit binding: No @Inject or default constructor found for com.jorsek.editor.gin.EditorClientFactory
所需节点的路径:
com.projectname.client.application.resourceworkspace。ResourceWorkspacePresenter [com.gwtplatform.mvp.client.gin.AbstractPresenterModule.bindPresenter (AbstractPresenterModule.java: 122)]-> com.jorsek.editor.gin.EditorClientFactory[@注入com.projectname.client.application.resourceworkspace.ResourceWorkspacePresenter的构造函数]
我是这样设置的:
我的工厂:
public interface EditorClientFactory {
/**
* Create a new DOMModel via assisted injection initializing the model
* with the document entity and it's DOM document content.
*
* @param document
* @param domDocument
* @return
*/
public DOMModel create(Entity document, Document domDocument);
}
我模块:public class EditorClientModule extends AbstractGinModule {
@Override
protected void configure() {
install(new GinFactoryModuleBuilder().build(EditorClientFactory.class));
bind(DOMModel.class).to(SyncedDOMModel.class);
}
}
com.jorsek.editor.impl.SyncedDOMModel:
public class SyncedDOMModel implements DOMModel {
@Inject
private SyncedDOMModel(){} /* For GIN/GUICE */
@AssistedInject
public SyncedDOMModel(CollabClient client, CollabClientFactory collabFactory, @Assisted Entity ref, @Assisted Document domDoc){
}
}
这是我如何试图注入我的工厂使用:
@AssistedInject
public ResourceWorkspacePresenter(final EventBus eventBus, final MyView view, final MyProxy proxy, APIService apiService, EditorClientFactory editorFactory, @Assisted EntityLocator entityLocator) {
super(eventBus, view, proxy, ApplicationPresenter.TYPE_SetMainContent);
this.editorFactory = editorFactory;
this.apiService = apiService;
System.out.println("E Locator: " + entityLocator);
}
这就是我如何使用我的工厂(从来没有得到这么远):
editorFactory.create(doc, domDoc);
有人知道为什么会发生这种情况吗?
如果有帮助的话,我正在使用GWTP RC2。
谢谢,凯西
你的代码是不正确的(我不知道它是否会解决你的问题,但这是一个开始):你不应该bind(DOMModel.class)
,而是告诉工厂:
install(new GinFactoryModuleBuilder()
.implement(DOMModel.class, SyncedDOMModel.class)
.build(EditorClientFactory.class));