[1.2.4] [guice] Guice configuration error: No implementation for java.util.List was bound

4,666 views
Skip to first unread message

Martin Grotzke

unread,
Apr 26, 2012, 9:31:36 AM4/26/12
to play-fr...@googlegroups.com
Hi,

I'm using the guice module and I'm just trying to inject a list into my
controller, but I'm getting an exception

ERROR ~ Guice configuration errors:

1) No implementation for java.util.List was bound.
while locating java.util.List


This is my controller:

...
import javax.inject.*;

public class Application extends Controller {

@Inject
@Named("myItems")
static List<String> items;

public static void index() {
render(items);
}

}

This is the module:

public class MyModule extends AbstractModule {
@Override
protected void configure() {
bind(new TypeLiteral<List<String>>()
{}).annotatedWith(Names.named("myItems")).toInstance(Arrays.asList("bar", "baz"));
}
}

I tested the same with a simple guice setup (without play) and there it
works fine.

Is this just not supported by the play guice module, or is it a bug?

Cheers,
Martin

signature.asc

Christian Kaps

unread,
May 10, 2012, 3:54:48 AM5/10/12
to play-framework
Hi,

have you found any solution for this problem? I have the the same
problem using provider methods.

As mentioned in the following thread it should actually work:
https://groups.google.com/forum/#!msg/play-framework/gqxUiYVjIA0/EGYHfaZPkqcJ

Cheers,
Christian


On Apr 26, 3:31 pm, Martin Grotzke <martin.grot...@googlemail.com>
wrote:
>  signature.asc
> < 1KViewDownload

Christian Kaps

unread,
May 10, 2012, 5:23:10 AM5/10/12
to play-framework
Hi,

after looking into the source code it seems not possible to use the
@Named annotation within controllers. The guice module can only inject
@Named instances into classes annotated with the @InjectSupport
annotation. The problem is that the instances for the static
controller fields will be injected by the play.inject.Injector class.
And this play framework class doesn't support the @Named annotation.

Cheers,
Christian


On May 10, 9:54 am, Christian Kaps <kaps.christ...@googlemail.com>
wrote:
> Hi,
>
> have you found any solution for this problem? I have the the same
> problem using provider methods.
>
> As mentioned in the following thread it should actually work:https://groups.google.com/forum/#!msg/play-framework/gqxUiYVjIA0/EGYH...

Christian Kaps

unread,
May 10, 2012, 5:53:38 AM5/10/12
to play-framework
Hi,

as a workaround, it is possible to annotate a controller with the
@InjectSupport annotation.

- First try: guice prints an error message
- Second try: guice module injects the named instance successfully

Not nice, but it works (o;

Cheers,
Christian



On 10 Mai, 11:23, Christian Kaps <kaps.christ...@googlemail.com>
Reply all
Reply to author
Forward
0 new messages