Guice

Resteasy and Google Guice: how to use multiple @ApplicationPath and resource with @Injection?

霸气de小男生 提交于 2019-12-01 16:19:17
I created a project to test the dependency injection offered by Google Guice in my Jax-rs resources, using Resteasy. My intentions are: Use multiple @ApplicationPath for the versions of my API. In each class annotated with @ApplicationPath I load a set of classes for the specific version. Each resource have a @Inject (from Google Guice) in his constructor to inject some services. I created two classes annotated with @ApplicationPath : ApplicationV1RS and ApplicationV2RS . In both I added the same resources classes ( UserResource and HelloResource ), only for my test. My Module is configured

Weblogic 12c : Prefer-web-inf-classes and prefer-application-packages for Jersey

给你一囗甜甜゛ 提交于 2019-12-01 15:53:03
问题 I have to use both (oddly enough ..) prefer-web-inf-classes and prefer-application-packages properties of weblogic.xml on a Weblogic 12c Server (12.2.1) It is REST application based on Jersey 1.9. ( Jersey 1.x JAX-RS RI) and Guice. 1. Why use :prefer-web-inf-classes If you have more than one WAR you have to place at the level of war/lib the libraries for guice-jersey / guice , other way you get an Multibindings Error. It must be indicated also the prefer-web-inf-classes to true . This way it

Resteasy and Google Guice: how to use multiple @ApplicationPath and resource with @Injection?

不羁的心 提交于 2019-12-01 15:16:36
问题 I created a project to test the dependency injection offered by Google Guice in my Jax-rs resources, using Resteasy. My intentions are: Use multiple @ApplicationPath for the versions of my API. In each class annotated with @ApplicationPath I load a set of classes for the specific version. Each resource have a @Inject (from Google Guice) in his constructor to inject some services. I created two classes annotated with @ApplicationPath : ApplicationV1RS and ApplicationV2RS . In both I added the

Jersey, Guice and Hibernate - EntityManager thread safety

泄露秘密 提交于 2019-12-01 14:13:13
I have used this tutorial them same way in my application: http://www.benmccann.com/hibernate-with-jpa-annotations-and-guice/ My app is JAX-RS web service which will receive many concurrent requests and make updates to database. GenericDAOImpl.java implementation: public class GenericDAOImpl<T> implements GenericDAO<T> { @Inject protected EntityManager entityManager; private Class<T> type; public GenericDAOImpl(){} public GenericDAOImpl(Class<T> type) { this.type = type; } @Override public void save(T entity) { entityManager.getTransaction().begin(); entityManager.persist(entity);

Guice: One “Provider<T>” for multiple implementations

喜夏-厌秋 提交于 2019-12-01 12:17:02
I have an interface that has 20 or so annotated implementations. I can inject the correct one if I know which I need at compile time, but I now need to dynamically inject one based on runtime parameters. As I understood the documentation, I would have to use 20 or so Provider<T> injections and then use the one I need, which seems rather excessive to me. Is there a way to have something like an inst(Provider<T>).get(MyAnnotation.class) to bind a specific implementation, and then have only that Provider injected into my class? Inject a MapBinder . In your module, load the bindings into the

Jersey and Google Guice integration

纵饮孤独 提交于 2019-12-01 12:11:58
My question is: why do I need to create AbstractModule when doing JavaSE application and ServletModule while creating application that is deployed on some kind of servlet container like jetty or tomcat? What are the differences between them? I need to integrate Jersey with Guice. Is it necessary to register presence of Guice for Jersey to use it somehow? Can't I just enable injections and do them everywhere I want (normal classes, filters, handlers, services, DAOs etc.)? And why can't I just configure guice like in JavaSE application, but instead need to use ServletModule? As far as I see on

Guice: One “Provider<T>” for multiple implementations

点点圈 提交于 2019-12-01 11:47:29
问题 I have an interface that has 20 or so annotated implementations. I can inject the correct one if I know which I need at compile time, but I now need to dynamically inject one based on runtime parameters. As I understood the documentation, I would have to use 20 or so Provider<T> injections and then use the one I need, which seems rather excessive to me. Is there a way to have something like an inst(Provider<T>).get(MyAnnotation.class) to bind a specific implementation, and then have only that

Deferred binding failed

大兔子大兔子 提交于 2019-12-01 11:02:42
My application is throwing: java.lang.RuntimeException: Deferred binding failed for 'com.mygwtapp.client.gin.ClientAppGinjector' (did you forget to inherit a required module?) on this code inside the EntryPoint: private final ClientAppGinjector injector = GWT.create(ClientAppGinjector.class); What could be the problem? Here's the full error Log: java.lang.RuntimeException: Deferred binding failed for 'com.mygwtapp.client.gin.ClientAppGinjector' (did you forget to inherit a required module?) at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53) at com.google.gwt.core.client

Multi tenancy with Guice Custom Scopes and Jersey

邮差的信 提交于 2019-12-01 10:31:50
I am in the process of developing a multi tenancy application with Jersey using Guice for DI (I also use Dropwizard but I don't think it matters here). One thing that bothers me is the fact that some kind of tenancy_id is all over the place in my application. Most of my URLs look like this: /:tenancy_id/some_resource/do_stuff . So the method in my Jersey resource is called with the tenancy_id and hands it over to a service which calls other services and so on. These services are configured differently for different tenants. I managed to resolve this problem by using a @RequestScoped

Jersey and Google Guice integration

冷暖自知 提交于 2019-12-01 10:07:00
问题 My question is: why do I need to create AbstractModule when doing JavaSE application and ServletModule while creating application that is deployed on some kind of servlet container like jetty or tomcat? What are the differences between them? I need to integrate Jersey with Guice. Is it necessary to register presence of Guice for Jersey to use it somehow? Can't I just enable injections and do them everywhere I want (normal classes, filters, handlers, services, DAOs etc.)? And why can't I just