My project have some maven modules, one of that is the repository module, an other is the web module. In repository module I'm using the google guice to do the dependency injection, and any more. In web module I'm using the tomEE, and that module have all others (api, services and repositories). My problem was in repository module, when I would inject the EntityManager object in repositories, to solve this problem I put in the implementation of Guice AbstractModule it: bind(EntityManager.class).annotatedWith(ConnectionDatabase.class).to(EntityManager.class);
What do you thing about? Thank you for the attention! Em quarta-feira, 28 de setembro de 2016 19:47:57 UTC-3, scl escreveu: > > I am not 100% sure but I think guice does not support the @Produces > annotation. > So far I only used @Provides > > Also if you are using tomEE you already have a CDI container. What is your > reason to use guice in such an environment. > > Don't missunderstand me. I prefer guice over CDI but why chose tomEE and > then don't use its feature... > > Am 28. September 2016 19:36:28 MESZ, schrieb "Robério Cardoso Fernandes" < > [email protected] <javascript:>>: >> >> I'm doing the integration tests with Apache OpenEJB (tomee). The bind is >> done when the container is started. >> >> >> >> Em quarta-feira, 28 de setembro de 2016 14:12:46 UTC-3, scl escreveu: >>> >>> Where do you bind the EntityManager? Is it bound just in time? At >>> runtime do you have a container or similar which provides the EntityManager? >>> >>> Am 28. September 2016 17:20:16 MESZ, schrieb "Robério Cardoso Fernandes" >>> <[email protected]>: >>>> >>>> Hi folks, >>>> I'm doing the unit tests in my project, and I'm trying to use the >>>> Google Guice. My repository classes have your EntityManagers, and, in my >>>> project, to specify the persistence unit I have an annotation: >>>> >>>> @javax.inject.Qualifier >>>> @java.lang.annotation.Retention(RUNTIME) >>>> @java.lang.annotation.Target({FIELD, TYPE, METHOD}) >>>> public @interface ConnectionDatabase { >>>> } >>>> >>>> >>>> In my repositories the entity managers are injected like this: >>>> >>>> public class MyRepository implements IMyRepository { >>>> >>>> @javax.inject.Inject >>>> @ConnectionDatabase >>>> private javax.persistence.EntityManager entityManager; >>>> } >>>> >>>> >>>> M ResourceProducer, like this: >>>> >>>> public class ResourceProducer { >>>> >>>> @javax.enterprise.inject.Produces >>>> @Inject >>>> @ConnectionDatabase >>>> private javax.persistence.EntityManager entityManager; >>>> } >>>> >>>> >>>> My Module of Google Guice is like this: >>>> >>>> public class ModuleTest extends AbstractModule { >>>> >>>> @Override >>>> public void configure() { >>>> bind(new TypeLiteral<IMyRepository>() >>>> {}).to(MyRepository.class); >>>> } >>>> } >>>> >>>> >>>> I have a persistence.xml with a persistence unit called "TestPU". >>>> >>>> >>>> In my unit tests (or cintegration tests), using the Google Guice, the >>>> EntityManager is not injected, and the following error is occurring: >>>> No implementation for javax.persistence.EntityManager annotated with >>>> @ConnectionDatabase() was bound. >>>> while locating javax.persistence.EntityManager annotated with >>>> @ConnectionDatabase() >>>> for field at MyRepository.entityManager(<the line>) >>>> at ModuloTest.configure(<the line of the bind "bind(new >>>> TypeLiteral<IMyRepository>() {}).to(MyRepository.class)">) >>>> >>>> >>>> Someone here can help me, please? >>>> >>>> -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/google-guice. To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/eeb80f3e-2d84-429a-9a08-721dd314b72b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
