Guice

MyBatis-guice 3.3 + Multiple datasources + properties + scriptrunner

元气小坏坏 提交于 2019-12-21 20:46:24
问题 I'm using MyBatis-guice 3.3 to connect to a first database using a java Properties object and a ScriptRunner to run few scripts: Environment environment = injector.getInstance(SqlSessionFactory.class).getConfiguration().getEnvironment(); DataSource source = environment.getDataSource(); ScriptRunner runner = new ScriptRunner(source.getConnection()); runner.setLogWriter(null); runner.setStopOnError(true); runner.runScript(Resources.getResourceAsReader(properties.getProperty("script.dbA.create

How to use Guava ServiceManager with Guice Injection

不想你离开。 提交于 2019-12-21 17:30:40
问题 As mentioned here, Guava ServiceManager can be obtained by ServiceManager manager = injector.getInstance(ServiceManager.class); To make this work, I added the following in my Guice module: @Provides public Set<Service> services(){ return ImmutableSet.<Service>of(MyService()); } In my main class, ServiceManager manager = injector.getInstance(ServiceManager.class); manager.startAsync().awaitHealthy(); How do I get instances of the started services? p.s. Setting the services to be @Singleton

Transactions with Guice and JDBC - Solution discussion

情到浓时终转凉″ 提交于 2019-12-21 17:07:33
问题 In my application, I need to use pure JDBC together with Guice. However, Guice doesn't provide any built-in support to manage transactions. guice-persist only provides support based on JPA, which I cannot use. so I tried to implement a simple solution to manage transactions with Guice and JDBC. here is the first version: use TransactionHolder to store the transaction per thread. public class JdbcTransactionHolder { private static ThreadLocal<JdbcTransaction> currentTransaction = new

Guice equivalent of Spring's @Autowire list of instances

a 夏天 提交于 2019-12-21 12:19:56
问题 In spring when I do: @Autowire List<MyInterface> myInterfaces; then this list will get populated by all beans which implement MyInterface . I didn't have to create bean of type List<MyInterface> . I'm looking for such behaviour in Google Guice. Sofar I went with: Multibinder<MyInterface> myInterfaceBinder = MultiBinder.newSetBinder(binder(), MyInterface.class); Now if I have a bean which implements MyInterface and I bind it, say via: bind(MyInterfaceImpl.class).asEagerSingleton(); it won't be

Bind list of objects using Guice + Kotlin

吃可爱长大的小学妹 提交于 2019-12-21 11:55:14
问题 I'm writing a JavaFX application in Kotlin with the following controller definition: class MainController { @Inject private lateinit var componentDescriptors: List<ComponentDescriptor> /* More code goes here */ } I'm using Guice for Dependency management. And I'm trying to inject the list of class instances loaded via java.util.ServiceLoader . My problem is to define a binding that will inject the list of loaded object instances into the declared field. I tried annotation based provisioning:

What is the Spring equivalent to FactoryModuleBuilder, @AssistedInject, and @Assisted in Guice?

五迷三道 提交于 2019-12-21 09:12:23
问题 What is the Spring Framework equivalent to FactoryModuleBuilder, @AssistedInject, and @Assisted in Google Guice? In other words, what is the recommended approach using Spring to create factory objects whose methods accept arguments that the application (not the container) must provide? The Spring static factory method is not the same as FactoryModuleBuilder . FactoryModuleBuilder builds a Guice module that generates "factories" that implement the Factory Method Pattern. Unlike a Spring static

Guice proxying to support circular dependency

早过忘川 提交于 2019-12-21 08:25:44
问题 I'm getting the following error in my code at launch: Tried proxying com.bar.Foo to support a circular dependency, but it is not an interface. How exactly does this proxying work? If I just throw enough classes behind interfaces, will everything be fine? (I know that circular dependencies are usually a code smell, but I think in this case it's ok.) 回答1: While the "inject an interface" approach is totally valid, and might even be the better solution in some occasions, in general, you can use a

Guice proxying to support circular dependency

做~自己de王妃 提交于 2019-12-21 08:24:48
问题 I'm getting the following error in my code at launch: Tried proxying com.bar.Foo to support a circular dependency, but it is not an interface. How exactly does this proxying work? If I just throw enough classes behind interfaces, will everything be fine? (I know that circular dependencies are usually a code smell, but I think in this case it's ok.) 回答1: While the "inject an interface" approach is totally valid, and might even be the better solution in some occasions, in general, you can use a

Long lasting 'COMMIT' queries with 'idle' state in pg_stat_activity

回眸只為那壹抹淺笑 提交于 2019-12-21 07:44:06
问题 If I query: select * from pg_stat_activity where application_name ~ 'example-application'; I get many rows which state is idle and query is COMMIT . They are long lasting and do not disappear. After some time, my application reach hibernate.c3p0.max_size (maximum number of JDBC connections in the pool) limit and stops working with database. Some application implementation details are described in other SO thread: Guice DAO Provider in thread pool - queries become 'idle in transation' Why does

What is the clojure equivalent to google guice?

╄→尐↘猪︶ㄣ 提交于 2019-12-21 07:11:01
问题 I came across google guice and could not really understand it and what it did, although there seems to be alot of hype around it. I was hoping to get a clojurian perspective of the library and why it is needed/not needed in clojure applications and if there was anything similar built into the language. 回答1: Because of Java's OO and type system, dynamically switching between different underlying implementations (for test (mocking) purposes for instance) can be difficult to manage. Libraries