Yes, this is the exact solution that I just found! I also created a helper class and set its Injector from GuiceServletContextListener when it gets initialized.
Thanks, Tushar Bhasme On Wed, Dec 3, 2014 at 3:49 PM, <[email protected]> wrote: > The only working way we found was this: > > > > package something; > > import java.io.Serializable; > import java.util.Collections; > import java.util.Set; > import java.util.stream.Collectors; > > import org.hibernate.envers.DefaultRevisionEntity; > import org.hibernate.envers.EntityTrackingRevisionListener; > import org.hibernate.envers.RevisionType; > import org.slf4j.Logger; > import org.slf4j.LoggerFactory; > > import com.google.inject.Inject; > ... > > public class AuditListener implements EntityTrackingRevisionListener { > > private static final Logger log = LoggerFactory.getLogger( > AuditListener.class); > > @Inject > private RevMasterChangeDAO revMasterChangeDAO; > > public AuditListener() { > super(); > // this is not created by guice but somehow instatiated by > hibernate envers > // therefore injection does not work out of the box > // the following statement injects manually all members in this. > // TODO find a better way to integrate this in guice > > try { > InjectorHolder.getInjector() > .injectMembers(this); > } catch (Exception e) { > log.warn(e.getMessage(), e); > } > > } > > public AuditListener(boolean dontInject) { > super(); > // use this constructor for tests, if mocks are injected with and > via mockito > } > snip > > InjectorHolder looks like this: > /** > * Holds instance of the Guice injector. Should be filled after > initialization > * of Injector (after calling createInjector()) > */ > public final class InjectorHolder { > > private static Injector staticInjector; > > private InjectorHolder() { > } > > public static void setInjector(Injector injector) { > staticInjector = injector; > } > > public static Injector getInjector() { > return staticInjector; > } > > > > -- > You received this message because you are subscribed to a topic in the > Google Groups "google-guice" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/google-guice/Yp1xbCM37jY/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/google-guice. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-guice/3925d1c3-f452-4719-9803-aa402c84840d%40googlegroups.com > <https://groups.google.com/d/msgid/google-guice/3925d1c3-f452-4719-9803-aa402c84840d%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice. To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/CANHgFbf4EK54NVKNDXrNfJZcpDeEp%3D%3Dg2%2BtMYXHy0-U7wEH4QQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
