Reputation: 2223
I have been trying to use Google Guice in eclipse plug-in development. I have imported Guice jar as another plug-in project. But somehow Guice is unable to inject dependency.
Any ideas???
This is the error message
com.google.inject.ConfigurationException: Guice configuration errors:
1) No implementation for java.util.List<java.lang.String> was bound.
while locating java.util.List<java.lang.String>
for parameter 1 at com.checker.extension.provider.util.PluginUtils.<init>(Unknown Source)
while locating com.checker.extension.provider.util.PluginUtils
1 error
EDIT1
One thing which I would like to mention is the configuration works correctly when I use normal Java application but it don't when I use plug-in project
EDIT2 Below is the code which I am using
@Override
protected void configure() {
bind(List.class).toInstance(DIObjects.buildFolderNames);
}
Here DIObjects.buildFolderNames
is the static field which I need to inject.
Defination of DIObjects.buildFolderNames is as follows.
public static List<String> buildFolderNames;
and I have initialized this field.
Is the problem is because of different classloaders of eclipse and Guice ???
Upvotes: 2
Views: 4348
Reputation: 114847
Looks like a configuration / annotation problem to me (at first sight). According to this article you have to annotate List
to specify what kind of list you want to inject.
If the binding is correct in your code, make sure, that the packages that include the binding / the annotation classes are properly exported and properly declared in the plugin configuration. Maybe Guice just can't see the bindings.
Upvotes: 2
Reputation: 6150
Works for me. But I did something different - I went to the SpringSource Enterprise Bundle Repository and downloaded their Guice 2.0 bundle and its sole dependency, the AOP Alliance API 1.0.0 bundle. Then I added a dependency from my plugin to the Guice bundle. I created a static member variable like yours, initialized to a short list of strings, and bound it to List; then, in a TableViewer, created a content provider that gets the injector and calls getInstance(List.class), converting the return value to an array and returning it. The result: my strings visible in the table.
Here are links to the pages for the two bundles. On each page are links to the binary and source jars. Get either; import them into your workspace; add a dependency from your bundle to the Guice bundle; that ought to do it.
Upvotes: 2
Reputation: 12049
You need to use a TypeLiteral to perform such a binding, for example:
bind(new TypeLiteral<List<String>>(){}).toInstance(new ArrayList<String>());
More info regarding bindings is available here.
Upvotes: 9
Reputation: 4336
Have you done something like this:
bind(List.class).to(ArrayList.class);
in your class that sets up your binings? Because List is just an Interface, so guice don't know what implementation to pick.
Upvotes: -2