Guice

Android/RoboGuice/Maven: ClassNotFoundException in Eclipse, but not from Maven command line

元气小坏坏 提交于 2019-12-22 10:32:26
问题 I have a class that handles Guice bindings. It is the very first thing that needs to run, called ApplicationAutoworkout.java. package com.redsoft.android.autoworkout; import java.util.List; import roboguice.application.RoboApplication; import com.google.inject.Module; import com.redsoft.android.autoworkout.service._ModuleQueryFor; import com.redsoft.android.autoworkout.service._ModuleService; import com.redsoft.android.autoworkout.ui._ModuleUi; public class ApplicationAutoworkout extends

URI-specific ExceptionMapper in JAX-RS

試著忘記壹切 提交于 2019-12-22 06:55:34
问题 I'm using Jersey, and Guice as my IOC-container. I'd like to know if it is possible to associate an ExceptionMapper with a specific URI. The reason for this is that I want to map the same exception differently based on what URI was visited. For example, suppose I've got the following two exception mappers for my custom exception: public class MyExceptionMapperForFirstURI implements ExceptionMapper<MyException> {..return response based on first URI..} public class MyExceptionMapperForSecondURI

Injecting dependencies to ServletContextListener with Guice

喜欢而已 提交于 2019-12-22 05:58:52
问题 Since ServletContextListener is created by the server, not by Guice I can't find a way to make it work together. How do I get guice injector at ServletContextListener? Maybe there is better way to shutdown services like logger or persistance then doing it at contextDestroyed method and initialize them at contextInitialized? 回答1: The extension GuiceServlet puts the injector in the servlet context, so you can get it by doing something like this: public class MyServletContextListener implements

How do I get google guice to inject a custom logger, say a commons-logging or log4j logger

纵然是瞬间 提交于 2019-12-22 05:14:29
问题 Google guice has a built-in logger binding. But what if I want to use a commons-logging or log4j logger? Can I get guice to inject a Log created by LogFactory.getLog(CLASS.class) But having the same behavior as in built-in binding: The binding automatically sets the logger's name to the name of the class into which the Logger is being injected.. Does it even makes sense? Or shout I simply use the built-in java Logger? Or just use commons-logging without injections? 回答1: The CustomInjections

How to do manual DI with deep object graphs and many dependencies properly

断了今生、忘了曾经 提交于 2019-12-22 04:45:17
问题 I believe this questions has been asked in some or the other way but i'm not getting it yet. We do a GWT project and my project leader disallowed to use GIN/Guice as an DI framework (new programmers are not going to understand it, he argued) so I try to do the DI manually. Now I have a problem with deep object graphs. The object hierarchy from the UI looks like this: AppPresenter->DashboardPresenter->GadgetPresenter->GadgetConfigPresenter The GadgetConfigPresenter way down the object

How do you make dynamic bindings in Guice that require an injected Instance?

不羁的心 提交于 2019-12-22 04:05:36
问题 I'd like to create a Module that dynamically binds instances to named annotations. The use case is I would like to automatically bind the values in my configuration with the key in the properties file being the @Named value. However the configuration is bound in a different module so I need the config to be injected. Solutions I've looked at are: Binding in the configure() method. This method is not injected into and I can not get the base configuration. Using a Provider/@Provides. Providers

How to test implementations of Guice AbstractModule?

随声附和 提交于 2019-12-22 03:55:29
问题 How to test implementations of Guice AbstractModule in a big project without creating fake implementations? Is it possible to test bind() and inject() methods? 回答1: Typically the best way to test Guice modules is to just create an injector in your test and ensure you can get instances of keys you care about out of it. To do this without causing production stuff to happen you may need to replace some modules with other modules. You can use Modules.override to selectively override individual

How to delegate creation of some classes from Guice injector to another factory?

喜你入骨 提交于 2019-12-22 03:38:50
问题 For instance, RESTEasy's ResteasyWebTarget class has a method proxy(Class<T> clazz) , just like Injector's getInstance(Class<T> clazz) . Is there a way to tell Guice that creation of some classes should be delegated to some instance? My goal is the following behavior of Guice: when the injector is asked for a new instance of class A, try to instantiate it; if instantiation is impossible, ask another object (e. g. ResteasyWebTarget instance) to instantiate the class. I'd like to write a module

No implementation was bound - Java Guice

六眼飞鱼酱① 提交于 2019-12-22 01:53:48
问题 Novice here trying to use a dummy Java Facebook app that uses Guice to inject a database dependency into the Facebook factory but continue to have Guice error out telling me: ### No implementation for com.example.storage.Db annotated with @com.example.storage.annotations.SystemDb() was bound while locating com.example.storage.Db annotated with @com.example.storage.annotations.SystemDb() for parameter 0 at com.example.facebook.client.exceptions.FacebookExceptionHandlerDb at com.example

Using Guice, how can I inject a bounded-wildcard class?

我的梦境 提交于 2019-12-21 23:41:00
问题 Using Guice, I want to inject a bounded-wildcard class. To be clear, I don't want to inject an object , but inject a class type . The would read: class A { Class<? extends SuperClass> a; @Inject A(Class<? extends SuperClass> a) { this.a = a.; } } How can I correctly bind the parameter? 回答1: Use this binding: bind(new TypeLiteral<Class<? extends SuperClass>>() {}) .toInstance(SubClass.class); 来源: https://stackoverflow.com/questions/8734826/using-guice-how-can-i-inject-a-bounded-wildcard-class