Guice

lombok and guice injection

荒凉一梦 提交于 2020-01-02 09:52:48
问题 I'm new to lombok and guice injection, I could get the general concept but I ran into some code which I don't understand and can't search due to the syntax. Following is the code, can someone help me understand this? import com.google.inject.Inject; import lombok.AccessLevel; import lombok.AllArgsConstructor; @AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__({ @Inject })) public class SomeClass { ... } Thanks! 回答1: This is going to add a constructor with all fields as

lombok and guice injection

醉酒当歌 提交于 2020-01-02 09:52:18
问题 I'm new to lombok and guice injection, I could get the general concept but I ran into some code which I don't understand and can't search due to the syntax. Following is the code, can someone help me understand this? import com.google.inject.Inject; import lombok.AccessLevel; import lombok.AllArgsConstructor; @AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__({ @Inject })) public class SomeClass { ... } Thanks! 回答1: This is going to add a constructor with all fields as

Using guice for a framework with injected classes, proper way to initialize?

我怕爱的太早我们不能终老 提交于 2020-01-02 07:45:48
问题 I'm trying to write a framework where arbitrary bean classes are injected with classes from my API, and they can interact with both those classes as well have triggered callbacks based on defined annotations. Here's an example bean: @Experiment static class TestExperiment { private final HITWorker worker; private final ExperimentLog log; private final ExperimentController controller; @Inject public TestExperiment( HITWorker worker, ExperimentLog expLog, ExperimentController controller ) {

How to create recursive object graphs with Guice?

青春壹個敷衍的年華 提交于 2020-01-02 05:56:10
问题 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

JBoss AS7 Automatically Loading JPA

我只是一个虾纸丫 提交于 2020-01-02 04:51:09
问题 I have an application which uses JPA/Hibernate and Google Guice. Guice is bootstrapped in a ServletContextListener and it sets up the EntityManagerFactory itself. The application works fine on Tomcat 7, but when I deploy to JBoss AS7 it fails because JBoss decides to automatically setup JPA prior to invoking my ServletContextListener . How can I get JBoss to not initialize JPA automatically and instead wait for my ServletContextListener to do it? Update According to the link that James

use verify on mocked (with Mockito) objects inject by guice

荒凉一梦 提交于 2020-01-01 19:32:57
问题 I have unit test, i use guice for di, i annotate my class with : @Guice(modules = { BatchGuiceModule4Test.class }) public class TestOneDayBatchStarter { } My objects are well injected from my module like this one : @Inject private DataManager dataManager; In my module, I add a @Provides method : @Provides @Singleton public DataManager getDataManager() { LOG.debug("## init Mocked Data Manager"); DataManager dataManager = mock(DataManager.class); when(dataManager.getObjectCodeList()).thenReturn

Guice log4j custom injection does not support logging within the constructor

点点圈 提交于 2020-01-01 17:26:37
问题 I'm trying to use Guice to inject Log4J Logger instances into classes as described in the Guice documentation: http://code.google.com/p/google-guice/wiki/CustomInjections However, as noted in some of the comments on that wiki page, this scheme does not support a constructor injection. So I can't do this: public class Foo { @InjectLogger Logger logger; @Inject public Foo(<injected parameters>) { logger.info("this won't work because logger hasn't been injected yet"); ... } public bar() { logger

Guice log4j custom injection does not support logging within the constructor

你离开我真会死。 提交于 2020-01-01 17:26:13
问题 I'm trying to use Guice to inject Log4J Logger instances into classes as described in the Guice documentation: http://code.google.com/p/google-guice/wiki/CustomInjections However, as noted in some of the comments on that wiki page, this scheme does not support a constructor injection. So I can't do this: public class Foo { @InjectLogger Logger logger; @Inject public Foo(<injected parameters>) { logger.info("this won't work because logger hasn't been injected yet"); ... } public bar() { logger

Guice injected EntityManager in multi threaded application

半城伤御伤魂 提交于 2020-01-01 17:25:09
问题 I'm working on a desktop application using Java SE 7. The application uses multiple threads and in each thread that is created a DAO class is injected to gain access to my database. As persistence layer i'm using EclipseLink and JPA. The EntityManager is injected into my DAO class using constructor injection and since it is not thread safe, I went for the approach using a Provder like this: public PluginInstanceJpaController implements IPluginInstanceDao { private EntityManager em; @Injected

guice: runtime injection/binding at command line

人走茶凉 提交于 2020-01-01 15:05:43
问题 I have the following problem: @Inject MyClass(Service service) { this.service = service; } public void doSomething() { service.invokeSelf(); } I have one module bind(service).annotatedWith(Names.named("serviceA").to(ServiceAImpl.class); bind(service).annotatedWith(Names.named("serviceB").to(ServiceBImpl.class); Now my problem is I want to allow user to dynamically choose the injection on runtime base through command line parameter. public static void Main(String args[]) { String option = args