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
The main problem here is that you’re using
@Providesincorrectly. An@Providesmethod must be in one of theModules that you use when initializing Guice… you can’t just put it in theGuiceServletContextListener.