Guice

guice injection in static variable

女生的网名这么多〃 提交于 2019-12-23 07:31:38
问题 I Have doubt about guice injection. Is it possible to inject a @named variable value to a static variable? I have tried @Provides @Named("emp.id") public Integer getEmpId() { return 2; } and tried to inject this value to static variable such as @Inject @Named("emp.id") private static Integer id; But the id return value null, When I removed static modifier the id gave value 1. What is really happening here? 回答1: Guice does not inject static fields by design. You can request static injection

How to use Guice's Injector?

こ雲淡風輕ζ 提交于 2019-12-23 07:26:30
问题 I'm in process of learning Guice and I don't clearly understand how to use Injector instance. It's better to create Injector instance once on application bootstrap, and make it public singleton? And is it true that we always must use Injector#getInstance(SomeClass.class) to get classes where we putted Guice's @Inject annotations? 回答1: You should not pass the injector around as a global singleton. Have you looked at: https://github.com/google/guice/wiki/GettingStarted? Note that

How to use Guice's Injector?

北战南征 提交于 2019-12-23 07:25:05
问题 I'm in process of learning Guice and I don't clearly understand how to use Injector instance. It's better to create Injector instance once on application bootstrap, and make it public singleton? And is it true that we always must use Injector#getInstance(SomeClass.class) to get classes where we putted Guice's @Inject annotations? 回答1: You should not pass the injector around as a global singleton. Have you looked at: https://github.com/google/guice/wiki/GettingStarted? Note that

Google Guice and varying injections at runtime

只愿长相守 提交于 2019-12-23 05:32:29
问题 I'd like to vary the injected implementations based on something that's not known until runtime. Specifically, I'd like my app to operate as different versions where the "version" is not determined until a request is executing. Also, the "version" could vary per request. After reading the docs it seems that I could implement a providers in cases where I need to choose an implementation at runtime based on the "version". Additionally, I could roll my own on top of juice. Is implementing a

Guice + Jersey integration injects null objects

蓝咒 提交于 2019-12-23 05:01:26
问题 Following the excellent step-by-step given in Up and running on AppEngine with Maven, Jersey and Guice - Part 3, I have been able to get everything working except injecting objects into a Jersey POJO. The only difference I have from that configuration is that I also have Objectify integrated, but that is working. The TestClass instance (a singleton) injected into HelloWorldServlet works, but the TestClass and SecondTest ( RequestScoped ) objects injected into the HeyResource POJO are always

Is there a way to inject ITestContext from TestNg to guice module?

血红的双手。 提交于 2019-12-23 04:47:24
问题 Let's say I have some guice module/provider which supposed to create bindings based on parameters received from TestNg suite file. e.g. <test name="Test"> <parameter name="profile" value="chrome"></parameter> <classes> <class name="com.apc.ui.tests.TestClass"> </class> </classes> </test> What I wanted to achieve is a possibility to access parameter value from withing above mentioned module. e.g. public class MyModule extends AbstractModule { @Inject ITestContext context; @Override protected

Guice AssistedInject won't inject the factory

坚强是说给别人听的谎言 提交于 2019-12-23 04:18:11
问题 I am trying to use Guice 3.0 AssistedInject , and it won't instantiate the factory. SSCCE Code: Parent class public class ParentClass() { @Inject private MyFactory myFactory; private final Foo foo; private final Bar bar; public ParentClass() { if(myFactory == null) System.err.println("Error: I should have injected by now!"); foo = myFactory.create(new Map<String, Object>()); // etc. } } Factory Interface public interface MyFactory { Foo create(Map<String, Object> mapA); Bar create(Map<String,

How to pass parameters to guicified TestNG test from Surefire Maven plugin?

瘦欲@ 提交于 2019-12-23 02:57:25
问题 I'm using Maven + Surefire + TestNG + Guice (latest stable ones) I have "large" test that requires Guice to run. Basically I'm doing it this way: @Test(groups = "large") @Guice(modules = FooLargeTest.Module.class) public class FooLargeTest { public static class Module extends AbstractModule { public void configure() { bindConstant().annotatedWith(FooPort.class).to(5000); // ... some other test bindings } } @Inject Provider<Foo> fooProvider; @Test public void testFoo() { Foo foo = fooProvider

Is it possible to use Spring Security with Google Guice?

我怕爱的太早我们不能终老 提交于 2019-12-23 01:03:37
问题 I would like to change Spring Framework to Google Guice, because it's lighter and has almost everything I need. Is it possible to use Spring Security with Google Guice instead of Spring Framework? 回答1: No. Spring Security makes extensive use of the core Spring Framework. (I guess, in theory you could use Spring + Spring Security for the security filters, and Google Guice for the servlet wiring ... but I expect there would be a few traps and pitfalls on that road.) 来源: https://stackoverflow

Shutdown Quartz scheduler

天涯浪子 提交于 2019-12-22 18:15:32
问题 I have Quartz scheduler in my web application with Guice. I followed code found here. Everything works fine, but I can't figure out how to shutdown scheduler. My context listener looks like this: public class MyAppContextListener extends GuiceServletContextListener{ @Override protected Injector getInjector() { return Guice.createInjector(new QuartzModule(), new MyAppServletModule()); } } And Quartz module looks like this: public class QuartzModule extends AbstractModule { @Override protected