deamon
deamon

Reputation: 92437

Guice @Provides method doesn't work

I have a method annotated with @Provides in my Guice config, but it doesn't work.

public class GuiceConfig extends GuiceServletContextListener {

  ...

  @Provides @RequestScoped
  EntityManager provideEntityManger() {
    return entityManagerFactory.createEntityManager();
  }

}

When I run my application I get the following error:

com.google.inject.CreationException: Guice creation errors:<|<|1) No implementation for javax.persistence.EntityManager was bound.<| while locating javax.persistence.EntityManager<|
for parameter 0 at com.someclass.of.myproject

Upvotes: 2

Views: 2164

Answers (1)

ColinD
ColinD

Reputation: 110054

The main problem here is that you're using @Provides incorrectly. An @Provides method must be in one of the Modules that you use when initializing Guice... you can't just put it in the GuiceServletContextListener.

Upvotes: 5

Related Questions