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

发布于 2024-11-16 12:57:24 字数 8481 浏览 4 评论 0原文

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

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;
}

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

这是完整的堆栈跟踪:

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)

谢谢。

I met very weird problem, using Gin injector in the client code return error with the following stack trace:

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?) 

Is it a gin issue or gwt ? In general is it available using java.util.list in the client side in gwt?

Here is an example how i use it.

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;
}

and then i do constructor injection and then got this exception.

Here is the full stack trace:

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)

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尹雨沫 2024-11-23 12:57:24

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

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

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

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

java.util.List is an interface not a concrete class, so GIN can not instantiate it. This is where the error is coming from.

Also, where is GIN supposed to get a list of SearchDTO?

You might work around this by adding this to your GinModule:

@Provides
List<SearchDTO> getSearchDTOList() {
    // do something to instantiate the list of SearchDTO..
    return listOfSearchDTO;
}
你げ笑在眉眼 2024-11-23 12:57:24

使用怎么样:
@Inject
公共数据源(ArrayList 用户){

}

更新
是的,通常可以在 GWT 客户端中使用 java.util.List 来实现。

在我的项目中,由于 JSON 序列化,我没有使用 List 作为接口。我没有尝试通过 GIN 注入它,这只是一个想法。
但现在我认为这不是一个好主意,因为这不是使用这种注射的方式。

编译什么时候出现错误?

what about using:
@Inject
public DataSource(ArrayList users) {

}

Update
Yes, in general is it available using java.util.List in the GWT client.

In my Project I am not using List as interface, because of JSON Serialization. I don't try injecting it via GIN, it was only an idea.
But now I think it is not a good idea, cuase it is not the way using this injection.

When do you get the error, compiling ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文