Guice

Is it possible to limit type hierarchy scanning with Guice?

 ̄綄美尐妖づ 提交于 2019-12-08 08:03:32
问题 Is there any way, when using Google's Guice injector to limit inheritance depth when scanning a class to find its dependencies ? I mean, if you define a class A like class A extends X { @Inject private B a; } And I got class inheritance : A --> X --> Y --> Z I just want A to be scanned, and X, but not upper classes like Y and Z. I am pretty certain no fields can be injected in neither classes. My goal is to boost startup phase. Is that possible ? 回答1: I don't think it's possible and I'd bet

Deferred binding failed error - Ginjector

怎甘沉沦 提交于 2019-12-08 07:39:46
问题 Hi I am having a problem with my gwt app, I am having the error below although I have this inherit: <inherits name='com.google.gwt.inject.Inject' /> Error: Caused by: java.lang.RuntimeException: Deferred binding failed for 'com.mygwtapp.client.gin.Injector' (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.GWT.create(GWT.java:98) at com.mygwtapp.client.Mygwtapp.onModuleLoad(Mygwtapp.java:29)

injecting generics with roboguice

旧城冷巷雨未停 提交于 2019-12-08 07:19:31
问题 I'm trying to inject instances with generics and i'm getting the following error: HasOne<ModelClass> cannot be used as a key; It is not fully specified. I've read elsewhere that safest way to do this is to explicitly name the class to be used in the generic when using the injector to get an instance but i'd like to be a little cleaner. I'm trying to create Relationship objects between Models . Here is my simplified Model class public class Model { @Inject Injector injector; public <ModelClass

Guice: Creating Injectors for Shared Libs

我的未来我决定 提交于 2019-12-08 06:56:31
问题 New to Google Guice. I'd like to use it to handle all IoC and AOP method interception for three components I am developing: WidgetClient - a Swing app WidgetServer - a small EAR that the client will connect to/communicate with WidgetShared - a "commons" JAR that contains common classes used by both client and server With the Swing app, somewhere I'll make an explicit call that might look like: public static void main(String[] args) { initGuiceInjectors(); } private static initGuiceInjectors()

Hibernate Validator: Intercept Invalid Values

≯℡__Kan透↙ 提交于 2019-12-08 06:31:49
问题 I'd like to set up my beans to use both Hibernate Validator (for validation) and Google Guice (for DI and method interception). Ideally, I'd like to have a setup where any method that "fails" validation will cause a method interceptor to be called: public class Widget { @NotNull public Fizz getFizz() { return fizz; } } public class FailedWidgetInterceptor implements MethodInterceptor { public Object invoke(MethodInvocation invocation) throws Throwable { // This gets executed if Widget's

Post creation initialization of guice singleton [duplicate]

半腔热情 提交于 2019-12-08 05:42:03
问题 This question already has answers here : Guice call init method after instantinating an object (7 answers) Configure an object provided by a Guice Module (2 answers) Closed 4 years ago . Is there a way to have guice call a init() method after it has instantiated a singleton? Calling init() inside the constructor is not an option since init() could be overriden by a subclass. 回答1: You can use `@PostConstruct' in guice when you use the mycila/jsr250 extension. This will cause your init() method

Jersey Test Framework & HK2-Guice bridge

99封情书 提交于 2019-12-08 05:22:44
问题 There are REST web service based on Jersey 2.23.2 & Guice 3.0. To use Guice it is necessary to adjust the hk2-guice bridge (I'm using 2.5.0-b07). Everything works fine until I have tried to test the service using Jersey Test Framework. Can't configure hk2-guice bridge for tests. My test: public class SomeTest extends JerseyTestNg.ContainerPerClassTest { @Override protected TestContainerFactory getTestContainerFactory() throws TestContainerException { return new GrizzlyWebTestContainerFactory(

@Nullable Ignored by guice

谁说胖子不能爱 提交于 2019-12-08 05:18:39
问题 I have a constructor like @Inject public FxManagerFactory(DataServicesClientAPI dsApi, OptimisationHorizon horizon, Logger logger, ModelScenario modelScenario, @Nullable LimDataProvider limDataProvider ){...} and I am getting this error null returned by binding at com.eet.mpm.portopt.domainmodel.modelrunners.PomModule.bindFactories(PomModule.java:171) but parameter 4 of com.eet.mpm.portopt.domainmodel.marketdata.FxManagerFactory.<init>() is not @Nullable while locating com.eet.mpm.pricecurves

Is it possible to inject an object with scala-guice?

▼魔方 西西 提交于 2019-12-08 04:53:28
问题 I would like to inject the scala.io.Source but I failed to find a working solution. This is what I have so far: class Foo @Inject()(var source:Source) { // ... } And the binding: class DependencyInjection extends AbstractModule with ScalaModule { def configure:Unit = { bind[Source.type].to[Source] // bind[Source] didn't work } } Maybe I can wrap the scala.io.Source calls into a local class but it doesn't sound right. Is there a way to inject objects with scala-guice? 回答1: Because Source is an

How to inject parameters into a class/trait method in Scala

爷,独闯天下 提交于 2019-12-08 03:42:03
问题 I have a code in my Play Scala (2.5x, 2.11.11) app which has been running just fine so far (it is based on the following link: https://fizzylogic.nl/2016/11/27/authorize-access-to-your-play-application-using-action-builders-and-action-functions/). But now I need to pass another class instance to ApplicationAuthorizationHandler class (NOTE: throughout my code I am using Guice DI for injecting parameters into class constructors). Current code: class ApplicationAuthorizationHandler extends