java - Error in binding: No implementation was bound - Guice -


i’m trying use guice solve dependency. i’ve read through tutorials , examples, still can’t figure out why keep getting error:

no implementation com.edit.owl.persistence.persistentstore<com.edit.common.domain.foo> annotated @com.google.inject.name.named(value=foopersistence) bound. while locating com.edit.owl.persistence.persistentstore<com.edit.common.domain.foo> annotated @com.google.inject.name.named(value=foopersistence) parameter 0 @ com.edit.owl.service.fooservice.<init>(fooservice.java:17)while locating com.edit.owl.service.fooservice parameter 0 @ com.edit.owl.resource.distributionlistresource.<init>(listresource.java:36)while locating com.edit.owl.resource.listresource 

so, basically, structure of code follow:

entity: foo

• fooservice

@singleton public class fooservice implements persistentstore<foo> { private final persistentstore<foo> foodao;  @inject public fooservice (@named("foopersistence")persistentstore<foo> foorepository) {     this.foodao = foorepository; }  @override @transactional public foo create(foo foo) {     return foodao .create(foo); }  @override @transactional public foo update(foo foo) {     return foodao.update(foo); }  @override @transactional public foo findbyid(long id) {     return foodao.findbyid(id); } } 

• persistentstore defines create, update , delete generic datatype e • fooresource client application calls fooservice

i have implemented binding in

• foomodule

public class foomoduleimplements module {   public void configure(final binder binder) {      binder.bind(fooresource.class);   } } 

• persistencemodule

public class persistencemodule extends abstractmodule { private final string persistenceunit;  public persistencemodule(string persistenceunit) {     this.persistenceunit = persistenceunit; }  @override protected void configure() {     install(new jpapersistmodule(persistenceunit));     bind(jpainitializer.class).aseagersingleton();      bind(new typeliteral<persistentstore<foo>>() {     }).to(new typeliteral<foo>() {     });  } 

}

how can fix problem?

in persistencemodule bind persistencestore without annotation. in constructor of fooservice ask dependency annotated @named("foopersistence").

either use annotations in both binding , injection point or remove them.

by way: prefere onami persist if have chance. fixes known bugs in guice persist (which abandoned).


Comments