Guice

Is it possible to automatically clean up resources at the end of scope in Guice?

限于喜欢 提交于 2019-12-06 17:15:19
问题 Let's say I have a Closeable object injected through Guice using request scope: @Provides @RequestScoped public MyCloseableResource providesMyCloseableResource(){ return new MyCloseableResourceImpl(); } Is it possible to hook-up a clean-up method that would automatically call close() on my resource when the scope exists, without resorting to custom scope implementation? Looking at the custom scope implementation guide on the Guice wiki, it shows that scopes should be created and cleaned up

Playframework & Guice without routing

坚强是说给别人听的谎言 提交于 2019-12-06 14:14:12
问题 I would like to know if it's possible to inject dependencies using Guice without having to pass by the routing. If it is how can I call my class Test @Inject()... within my application ? 回答1: I think there are two ways to use Guice in Play framework: 1) Directly instantiate an object based on the binding: Add Guice to your Build.scala app dependencies val appDependencies = Seq( "com.google.inject" % "guice" % "3.0" ) Create a Global class, which extends GlobalSettings, and bind interface to

JAX-WS and Guice 3

谁都会走 提交于 2019-12-06 10:18:12
问题 Is there some way to take SOAP web service classes creates with JAX-WS and inject them with, say, Guice 3.0 (guice-persist) transactions or even just plain ol' dependency injection? The guiceyfruit package provided a @GuiceManaged annotation that made this possible with Guice 2.0, but guiceyfruit (from my testing) appears to be incompatible with Guice 3, and I don't think the project is active any longer. Perhaps because there is another way of doing this? Maybe a JSR standard way? 回答1: I

How to inject a “runtime” dependency like a logged in user which is not available at application boot time?

只谈情不闲聊 提交于 2019-12-06 08:53:13
I'm just not getting this: I use Gin in my java GWT app to do DI. The login screen is integrated into the full application window. After the user has logged in I want to inject the user object into other classes like GUI Presenters which I create, so I have some sort of runtime dependency I believe. How do i do that? One solution I can think of is sth like: class Presenter { @Inject Presenter(LoggedInUserFactory userFactory) { User user = userFactory.getLoggedInUser(); } } class LoggedInUserFactoryImpl { public static User user; User getLoggedInUser() { return user; } } So, when the user is

Guice SPI: find bindings by wildcard types

笑着哭i 提交于 2019-12-06 08:37:07
问题 Guice provides a means to find all bindings for a given type (Injector#findBindingsByType) and it also provides a TypeLiteral class from which it seems possible to construct a wildcard type. What I would like to do is find all bindings for some type that is parameterised by a wildcard type but I can't figure out how to do it. A look at the guice src suggests I might be barking up the wrong tree but I figured I'd ask around anyway... so for example given a type Foo<E extends Bar> BarImplOne

Google Auto Factory / Dagger Integration: Dependencies on injected code

…衆ロ難τιáo~ 提交于 2019-12-06 08:22:16
问题 It seems that Dagger doesn't explain at all how to deal with providing / managing auto generated code, such as what Google Auto Factory creates. Also the people at Google Auto don't really explain how to integrate back with Dagger so it's causing a pain for people like myself without very senior knowledge of how both libraries work. The problem I'm seeing is that when you are not providing fully qualified names to factories generated by Google Auto Factory, Dagger will not pick them up at all

Guice and JSF 2

那年仲夏 提交于 2019-12-06 07:41:47
I'm trying to use Guice to inject properties of a JSF managed bean. This is all running on Google App Engine (which may or may not be important) I've followed the instructions here: http://code.google.com/docreader/#p=google-guice&s=google-guice&t=GoogleAppEngine One problem is in the first step. I can't subclass the Servlet module and setup my servlet mappings there because Faces is handled by the javax.faces.webapp.FacesServlet which subclasses Servlet, not HttpServlet. So, I tried leaving my servlet configuration in the web.xml file and simply instantiating a new ServletModel() along with

Akka cluster setup with play framework

醉酒当歌 提交于 2019-12-06 07:32:32
I'm currently trying to implement a clustered play + akka implementation with an auto discovery service. However, I seem to be running into issues with the Guice DI loader that's included with play. The excerpt from their documentation states: https://www.playframework.com/documentation/2.5.x/ScalaAkka#Integrating-with-Akka While we recommend you use the built in actor system, as it sets up everything such as the correct classloader, lifecycle hooks, etc, there is nothing stopping you from using your own actor system. It is important however to ensure you do the following: Register a stop hook

Guice JPA - “This connection has been closed.” error

泄露秘密 提交于 2019-12-06 07:29:21
问题 After DB dropps an idle connection or DB is down and back up I'm receiving the following error in my webapp: javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: could not inspect JDBC autocommit mode at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1365) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1293) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:265) ... 60 more

Shutdown Quartz scheduler

可紊 提交于 2019-12-06 07:29:21
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 void configure() { bind(SchedulerFactory.class).to(StdSchedulerFactory.class).in(Scopes.SINGLETON);