Guice

Calling a service on startup in a Play application

放肆的年华 提交于 2019-12-10 12:49:39
问题 I have a Play 2.4 application. Trying to kick off a weekly task when application starts. The current recommendation is to do that in a constructor for an eagerly injected class (Guice). However, my task needs access to a service. How can I inject that service into my task without getting an error: Error injecting constructor, java.lang.RuntimeException: There is no started application ? 回答1: You need to use constructor injection in your ApplicationStart class and provide an ApplicationModule

Guice and JSF 2

流过昼夜 提交于 2019-12-10 10:55:14
问题 I'm trying to use Guice to inject properties of a JSF managed bean. This is all running on Google App Engine (which may or may not be important) I've followed the instructions here: http://code.google.com/docreader/#p=google-guice&s=google-guice&t=GoogleAppEngine One problem is in the first step. I can't subclass the Servlet module and setup my servlet mappings there because Faces is handled by the javax.faces.webapp.FacesServlet which subclasses Servlet, not HttpServlet. So, I tried leaving

Multibinding with generics

岁酱吖の 提交于 2019-12-10 10:45:25
问题 I am trying to create a Multibinder<A<? extends B>> . I have tried using Multibinder.newSetBinder(binder(), A.class) . The second parameter is a Class<T> so doing this in my guice module gives me a Type mismatch error. Multibinder<A<? extends B>> multibinder = Multibinder.newSetBinder(binder(), A.class) Is it possible to bind these kind of generic collections? Maybe I could use a different kind of Multibinder ? Does anyone have any ideas? 回答1: there is a version that takes a TypeLiteral final

Guice injectMembers method

这一生的挚爱 提交于 2019-12-10 03:59:52
问题 I understand the benefits of using constructor injection over setter injection but in some cases I have to stick with setter-based injection only. My question is how to inject members of all the setter-based injection classes using injector.injectMembers() method? //I am calling this method in init method of my application private static final Injector injector = Guice.createInjector(new A(), new B()); //Injecting dependencies using setters of all classes bound in modules A and B injector

Why do I have an error when I try to override a generic binding with Guice? (TypeLiteral)

前提是你 提交于 2019-12-10 03:26:44
问题 I'd like to override a generic type binding, but I allways got the same " No implementation was bound " error. I'm using roboguice 3. Here is a exemple of code that I use: public interface IParser<I, O> {} public class Parser1 implements IParser<String, String> { IParser<String, String> mParser; @Inject public Parser1(IParser<String, String> parser) { mParser = parser; } } public class Parser2 extends Parser1 { @Inject public Parser2(IParser<String, String> parser) { super(parser); } } public

Is Google Guice active?

瘦欲@ 提交于 2019-12-10 03:26:42
问题 There were no releases for over a year, not even minor bugfixes. Commits to the repository are infrequent and there have been no commits for last two months. Is it safe to start new project using this library? 回答1: There is a pretty fresh answer in their Google Group. And here are current issues tagged as 3.1 candidates. 回答2: Guice 4 is now in beta (see https://github.com/google/guice) 回答3: Good news everyone! Guice 4.0 released (https://github.com/google/guice/wiki/Guice40) 回答4: Guice is a

Play 2.0/2.1 for Java and dependency injection

我是研究僧i 提交于 2019-12-10 03:17:04
问题 We have a new Play 2.0 project and we are planning to introduce DI as we add some complex 3rd party integration code. There is a Guice plugin for Play 2.0 but it looks like it will be obsolete at 2.1 and I have a hunch that 2.1 is not that far anymore. https://github.com/typesafehub/play-plugins/tree/master/guice Is Guice a safe bet for Play 2.0/2.1 or should we consider other options? 回答1: I'd go with the 2.1 version, and the new controller instanciation from the Global object. Here is a

How to use ServletScopes.scopeRequest() and ServletScopes.continueRequest()?

倾然丶 夕夏残阳落幕 提交于 2019-12-09 16:29:09
问题 How is one supposed to use ServletScopes.scopeRequest()? How do I get a reference to a @RequestScoped object inside the Callable? What's the point of seedMap ? Is it meant to override the default binding? What's the difference between this method and ServletScopes.continueRequest()? 回答1: Answering my own question: ServletScopes.scopeRequest() runs a Callable in a new request scope. Be careful not to reference objects across different scopes, otherwise you'll end up with threading issues such

Java Generics Error: inconvertible types from command line compiler

隐身守侯 提交于 2019-12-09 15:43:32
问题 I have some Guice binding code using generics that compiles and functions fine from Eclipse's compiler, but not from the Java (command-line) compiler. I upgraded to the latest (1.7.0_01) Java SDK but still get the following error. [error] ...\BindCategorySelectorActivity.java:42: error: inconvertible types [error] (Class<? extends ListAdapterDataProvider<Row<? extends DatabaseItem>>>) CategoryDataProvider.class); [error] ^ [error] required: Class<? extends ListAdapterDataProvider<Row<?

Managing transactions in JavaSE with Hibernate and Guice

时光毁灭记忆、已成空白 提交于 2019-12-09 13:58:27
问题 I'm writing a rather simple application that uses GWT, Hibernate and Google Guice (with GIN). What I wanted to do is to have transactions managed using external manager (like using @Transactional in Spring), instead of using EntityManager#getTransaction . I tried using @Transactional , but it doesn't seem to work for me. I have EntityManager already injected using Providers , like this: /* import stuff */ public class DbProvider implements Provider<EntityManager> { public EntityManager get()