java - 客户端代码中包含 java.util.List 时的 Gin 问题

标签 java gwt dependency-injection gwt-gin

我遇到了非常奇怪的问题,在客户端代码中使用 Gin 注入(inject)器返回错误,并带有以下堆栈跟踪:

ERROR: Deferred binding result type 'java.util.List' should not be abstract. 
ERROR: Uncaught exception escaped. java.lang.RuntimeException: Deferred binding failed for 'java.util.List' (did you forget to inherit a required module?) 

这是 Gin 问题还是gwt问题?一般来说,可以在 gwt 的客户端使用 java.util.list 吗?

这是我如何使用它的示例。

public class DataSource
{

private final List<SearchDTO> users;
private List<String> header = new ArrayList<String>();

@Inject
public DataSource(List<SearchDTO> users)
{ 
  header.add("Name");
  header.add("Age");
  header.add("Address");
  this.users = users;
}

public List<SearchDTO> getUsers()
{
  return users;
}

public List<String> getTableHeader()
{
  return header;
}

然后我进行构造函数注入(inject),然后得到这个异常。

这是完整的堆栈跟踪:

ERROR: Deferred binding result type 'java.util.List' should not be abstract. 
ERROR: Uncaught exception escaped. java.lang.RuntimeException: Deferred binding failed for 'java.util.List' (did you forget to inherit a required module?)
    at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53)
    at com.google.gwt.core.client.GWT.create(GWT.java:98)
    at gmgsys.com.webcharge.client.gin.MyGinjectorImpl.create_Key$type$java$util$List$gmgsys$com$webcharge$client$model$SearchDTO$$_annotation$$none$$(MyGinjectorImpl.java:411)
    at gmgsys.com.webcharge.client.gin.MyGinjectorImpl.get_Key$type$java$util$List$gmgsys$com$webcharge$client$model$SearchDTO$$_annotation$$none$$(MyGinjectorImpl.java:425)
    at gmgsys.com.webcharge.client.gin.MyGinjectorImpl.create_Key$type$gmgsys$com$webcharge$client$DataSource$_annotation$$none$$(MyGinjectorImpl.java:211)
    at gmgsys.com.webcharge.client.gin.MyGinjectorImpl.get_Key$type$gmgsys$com$webcharge$client$DataSource$_annotation$$none$$(MyGinjectorImpl.java:222)
    at gmgsys.com.webcharge.client.gin.MyGinjectorImpl.getDataSource(MyGinjectorImpl.java:11)
    at gmgsys.com.webcharge.client.MyCellList$3.onSuccess(MyCellList.java:125)
    at gmgsys.com.webcharge.client.MyCellList$3.onSuccess(MyCellList.java:1)
    at net.customware.gwt.dispatch.client.DefaultDispatchAsync$1.onSuccess(DefaultDispatchAsync.java:33)
    at net.customware.gwt.dispatch.client.DefaultDispatchAsync$1.onSuccess(DefaultDispatchAsync.java:1)
    at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:232)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
    at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    at java.lang.Thread.run(Thread.java:662)
Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
    at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:503)
    at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
    at com.google.gwt.core.client.GWT.create(GWT.java:98)
    at gmgsys.com.webcharge.client.gin.MyGinjectorImpl.create_Key$type$java$util$List$gmgsys$com$webcharge$client$model$SearchDTO$$_annotation$$none$$(MyGinjectorImpl.java:411)
    at gmgsys.com.webcharge.client.gin.MyGinjectorImpl.get_Key$type$java$util$List$gmgsys$com$webcharge$client$model$SearchDTO$$_annotation$$none$$(MyGinjectorImpl.java:425)
    at gmgsys.com.webcharge.client.gin.MyGinjectorImpl.create_Key$type$gmgsys$com$webcharge$client$DataSource$_annotation$$none$$(MyGinjectorImpl.java:211)
    at gmgsys.com.webcharge.client.gin.MyGinjectorImpl.get_Key$type$gmgsys$com$webcharge$client$DataSource$_annotation$$none$$(MyGinjectorImpl.java:222)
    at gmgsys.com.webcharge.client.gin.MyGinjectorImpl.getDataSource(MyGinjectorImpl.java:11)
    at gmgsys.com.webcharge.client.MyCellList$3.onSuccess(MyCellList.java:125)
    at gmgsys.com.webcharge.client.MyCellList$3.onSuccess(MyCellList.java:1)
    at net.customware.gwt.dispatch.client.DefaultDispatchAsync$1.onSuccess(DefaultDispatchAsync.java:33)
    at net.customware.gwt.dispatch.client.DefaultDispatchAsync$1.onSuccess(DefaultDispatchAsync.java:1)
    at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:232)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
    at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    at java.lang.Thread.run(Thread.java:662)

谢谢。

最佳答案

java.util.List 是一个接口(interface)而不是具体类,因此 GIN 无法实例化它。这就是错误的来源。

另外,GIN 应该在哪里获取 SearchDTO 列表?

您可以通过将其添加到 GinModule 来解决此问题:

@Provides
List<SearchDTO> getSearchDTOList() {
    // do something to instantiate the list of SearchDTO..
    return listOfSearchDTO;
}

关于java - 客户端代码中包含 java.util.List 时的 Gin 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6439494/

相关文章:

android - Dagger + Kotlin 不注入(inject)

java - JVM 如何运行 if(condition && false) 语句?

tomcat - 如何在 Apache Tomcat 中的单个 JS 文件上设置 Expires HTTP header ?

css - 如何在 GWT 自定义日志记录区域中包装日志行?

java - Gradle:多项目和构建 WAR 文件

私有(private)成员的 C++14 单元测试(解除)分配

c# - 正确自动处理 Sql 连接

java - 带分页的 API 的 Stream 与 Iterator

java - Linux JVM 上对象的内在锁

java - Spring boot Multi-Tenancy 代码,具有隔离的客户端特定隔离