Guice

Get All the instance subclass of trait using Google Guice

依然范特西╮ 提交于 2019-12-08 03:30:14
问题 I am trying to get All the instances subclass of trait(interface). This trait have multiple implementation which are provided third party users. Is this possible to get All the instances subclasses without explicit binding because I don't have control, Implementation provided by third party users. ? I already saw the same question in which you need to bind explicitly. Code sample: import javax.inject.Inject import com.google.inject._ import scala.collection.JavaConversions._ object DemoApp

Guice:Binding Annotations with Attributes

落花浮王杯 提交于 2019-12-08 00:42:32
问题 Now I am reading Guice's official document, but I have some questions related to the chapter of Binding Annotation. This explains "Annotation with Attributes". But, I'm not sure of the explanation. Binding Annotations with Attributes Guice supports binding annotations that have attribute values. In the rare case that you need such an annotation: Create the annotation @interface. Create a class that implements the annotation interface. Follow the guidelines for equals() and hashCode()

Akka cluster setup with play framework

隐身守侯 提交于 2019-12-08 00:08:52
问题 I'm currently trying to implement a clustered play + akka implementation with an auto discovery service. However, I seem to be running into issues with the Guice DI loader that's included with play. The excerpt from their documentation states: https://www.playframework.com/documentation/2.5.x/ScalaAkka#Integrating-with-Akka While we recommend you use the built in actor system, as it sets up everything such as the correct classloader, lifecycle hooks, etc, there is nothing stopping you from

When using the guice servlet extension is it possible to react to servlet destruction?

[亡魂溺海] 提交于 2019-12-07 23:04:10
问题 I need to do some cleanup when guice servlet is removed. Is it possible to hook into the servlet destruction when using a guice servlet? I need to use the Injector to do the cleanup work. I can override the contextDestroyed method in GuiceServletContextListener , but then how do I get access to the injector? Is there a better way to react to servlet destruction? 回答1: I can override the contextDestroyed method in GuiceServletContextListener, but then how do I get access to the injector? You

Jersey + Guice can't mix non-jersey resources with jersey resources

微笑、不失礼 提交于 2019-12-07 17:22:17
问题 How can I use non-jersey resources with jersey resources with guice ? I want "/" to be handled by a plain servlet. But I want "/users" handled by jersey. Say I have a jersey resource with @Path("/users"). Using the following bindings will not work, it tries to map the "/" request using jersey which of course is not a jersey resource and I get 404. protected void configureServlets() { serve("/").with(LoginServlet.class); serve("/*").with(GuiceContainer.class, params); } All of the examples of

Registry optimization with Guice

我怕爱的太早我们不能终老 提交于 2019-12-07 13:20:13
问题 Hi! Today I thought about a kind of optimization and have some questions... Context : I'm developing in Java using Guice 2. In my web application, I have a registry of converter to convert on the fly to a certain type. A converter is described as follows: public class StringToBoolean implements Converter<String, Boolean> { @Override public Boolean convert(String from) { return Boolean.valueOf(from); } } My registry is none other than a Map: public class ConverterRegistryImpl implements

Java Generics : Is any meta information about the generic type preserved at runtime as well?

独自空忆成欢 提交于 2019-12-07 12:33:45
问题 Background My understanding of Java generics is it being completely a compile time feature (mainly focusing on type safety checks). The type information for any generic class is lost at runtime ( type erasure ). Still, i see many frameworks seem to leverage the type information at runtime as well. For example, google guice Providers. The guice provider can instantiate and provide new instances of it's generic type at runtime. class Container { @Inject public Container(Provider<Content>

Jersey-Guice doesn't process bound resources if injector is a child?

妖精的绣舞 提交于 2019-12-07 12:29:49
问题 I'm using Jersey-Guice to configure a Jersey app, following this template. Everything works fine if the Injector returned by the GuiceServletContextListener.getInjector() method is created by Guice.createInjector() . If that injector is instead the child of another injector, then the bound resources (e.g., MyResource in the code below) are never added to the Jersey ResourceConfig and Jersey crashes with a complaint about missing root resources. I don't think the bound resources are even

How to clear ResourceBundle cache

人走茶凉 提交于 2019-12-07 10:30:02
问题 This is a webapp running on Tomcat, using Guice. According to the docs we should be able to call ResourceBundle.clearCache(); to clear the ResourceBundle cache and presumably get the latest from the bundle property files. We have also tried the following: Class klass = ResourceBundle.getBundle("my.bundle").getClass().getSuperclass(); Field field = klass.getDeclaredField("cacheList"); field.setAccessible(true); ConcurrentHashMap cache = (ConcurrentHashMap) field.get(null); cache.clear(); // If

How do I apply a servlet filter when serving an HTML page directly?

混江龙づ霸主 提交于 2019-12-07 08:16:54
问题 First off, I'm using Google AppEngine and Guice, but I suspect my problem is not related to these. When the user connect to my (GWT) webapp, the URL is a direct html page. For example, in development mode, it is: http://127.0.0.1:8888/Puzzlebazar.html?gwt.codesvr=127.0.0.1:9997 . Now, I setup my web.xml in the following way: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:/