Guice

Guice : Inject an ArrayList of Strings

狂风中的少年 提交于 2019-12-06 01:49:01
I'm trying to inject an ArrayList of String s with the help of Guice. I want to show a panel with many RadioButtons (for example) where an user can select some services to activate. Once selected, I would like to get all the names of the selected services and add them into a list, and inject this list to the manager responsible to create the services. Here is an example: public class UIProviderModule extends ProviderServiceModule { private ArrayList<String> requestedServices; public UIProviderModule(ArrayList<String> requestedServices) { this.requestedServices = requestedServices; } @Override

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

牧云@^-^@ 提交于 2019-12-06 01:35: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> contentProvider) { //This works at Runtime... but How ??? //When type's are not even preserved at runtime,

Spring5 高级编程-第一章 Spring 介绍

时光毁灭记忆、已成空白 提交于 2019-12-06 00:58:14
第一章 Spring 介绍 1.1 什么是 Spring 1.1.1 Spring 框架的演变 1.1.2 反转控制或依赖注入 1.1.3 依赖注入的演变 1.1.4 除了依赖注入 1.2 Spring 项目 1.2.1 Spring 的起源 1.2.2 Spring 社区 1.2.3 Spring 工具套件 1.2.4 Spring Security 项目 1.2.5 Spring Boot 1.2.6 Spring 批处理和集成 1.2.7 许多其他项目 1.3 Spring 的替代品 1.3.1 JBoss Seam 框架 1.3.2 Google Guice 1.3.3 PicoContainer 1.3.4 JEE 7 部署 1.4 小结 来源: https://my.oschina.net/beborn/blog/3135165

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

孤人 提交于 2019-12-06 00:14:17
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 scanned, because the usual "INFO: Registering my.example.MyResource as a root resource class" doesn't

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

旧巷老猫 提交于 2019-12-05 23:34:06
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 jersey / guice I can find do something like serve("/rest/*".with(GuiceContainer.class, params); which

Guice : Set bindings from an XML file

删除回忆录丶 提交于 2019-12-05 22:28:08
I'm trying to use Guice and make all the bindings with the help of an XML file. In my module (let's say "CustomModule"), I would like to load an XML file and parse it to set all the bindings. I'm able to load the XML file and retrieve all the values needed (below is an exemple of my XML file), but I'm unable to use those values to bind(interfaceValue).to(implementationValue); . What I've tried so far: Load the XML file, retrieve all the values and use them as : bind(Class.fromName(Ivalue)).to(Class.fromName(Value)); where Ivalue is InterfaceFoo and Value is Foo . Load the XML file as a

how to auto-wire HibernateBundle with guice on dropwizard?

坚强是说给别人听的谎言 提交于 2019-12-05 22:01:48
问题 Im trying to configure hibernatebundle with guice/dropwizard and need help. Im using hubspot / dropwizard-guice / 0.7.0 3rd party library in addition to dropwizard lib. The code below obviously wont work and need help on figuring it out. How do I rewrite this so that hibernatebundle and ultimately, session factory, be auto injected to whatever bean that needs it. MyApplication.java public class MyApplication extends Application<MyAppConfiguration> { private final HibernateBundle

How to create recursive object graphs with Guice?

送分小仙女□ 提交于 2019-12-05 18:12:29
Suppose I have 5 classes A, B, C, D, E that all implement a common interface X. Each of the classes B, C, D and E has a field of type X (so they can be seen as wrapper classes). Which instances are created is determined at runtime, so I could have for example one of the following object graphs: E -> D -> C -> B -> A D -> B -> A E -> A A (The order is fixed and the innermost instance is always of type A, but otherwise there are no restrictions.) No I'd like to create this objects with Guice to avoid providing all their other dependencies by hand. What's the easiest way to do this? Currently it

How to clear ResourceBundle cache

折月煮酒 提交于 2019-12-05 17:09:51
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 i debug here I can see the cache is now empty! and ResourceBundle.clearCache(this.class.getClassLoader

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

大兔子大兔子 提交于 2019-12-05 15:27:03
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://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display