Questions tagged [guice]

Guice is a lightweight dependency injection framework for Java.

Google Guice

Guice is Google's lightweight dependency injection framework. It is an open source software framework for the Java platform, compatible with Java 5 and above, released by Google under the Apache License.

It provides support for dependency injection using annotations to configure Java objects. Guice allows implementation classes to be programmatically bound to an interface, then injected into constructors, methods or fields using an @Inject annotation. When more than one implementation of the same interface is needed, the user can create custom annotations that identify an implementation, then use that annotation when injecting it.

Starting with version 3.0, Guice implements the JSR-330 standard of dependency injection for the Java platform.

References

Related Tags:

3211 questions
1
vote
1 answer

Google Guice binding not working with Integer and Long

Error when using Google Guice. Could not find a suitable constructor in java.lang.Long. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private. at…
Abhishek N
  • 35
  • 1
  • 3
1
vote
0 answers

Guice - Is there a way to inject a new instance of a dependent object into a Singleton?

I have a class that has been configured to be a Singleton, like this: @Singleton public class MySingleton { public MySingleton(MyDependency dependencyObj) { // ... } } Is there a way to get a new instance of MyDependency injected into the…
1
vote
3 answers

Jmeter cant read custom JAR depedencies

I wrote a Maven application that I want to use in my Jmeter BeanShell script. The Maven application is using Google Guice 4.2.2 for dependecy injection and it is calling an API at the end (Code needs to perform some other operations before calling…
click
  • 447
  • 1
  • 7
  • 25
1
vote
0 answers

Provider org.ehcache.jcache.JCacheCachingProvider not a subtype in Tomcat /lib

When using ehcache as a regular dependency and having it loaded with the WAR/lib folder things are good. But as described on the ehcache site, when attempting to re-deploy we are getting memory leak…
kendavidson
  • 1,430
  • 1
  • 11
  • 18
1
vote
1 answer

Guice: use the same instance independently and inside the binder

Is it possible to create one singleton object, and being able to inject it independently as the one instance, or as a part of set or map? For example, I have two instaces like this: @Provides @Singleton @Named(value = "bike.listener") fun…
Whizzil
  • 1,264
  • 6
  • 22
  • 39
1
vote
0 answers

Generating custom _id in protobuf java to save it in Mongodb

I am generating models to be saved in MongoDB using protobuf java. I want to generate a custom _id field. Can anyone let me how to achieve this? I have tried adding the _id field, but it is not working as expected. syntax = "proto3"; message User { …
1
vote
2 answers

Cross-Activity references using GWT with Gin

I have a GWT MVP application using Activities and Places. This is inspired by Mauro Bertapelle's sample (in this thread), apparently based on some of Thomas Broyer's work. Here's the problem: I have LoginActivity make an RPC call, which for a…
Glenn
  • 6,455
  • 4
  • 33
  • 42
1
vote
1 answer

How to load resources.properties from local directory, not the JAR in Java?

I have a Java application using Guice and JavaFX that requires configurable resources. I am trying to load multiple resources using…
1
vote
1 answer

Best practices for using jersey client via guice injection

I'm using Jersey-2.19.x in my application to call rest APIs. Since jersey clients are expensive to create, I wanted to reuse the client for my API calls and therefore inject the client via guice injection. Here is my guice code for injecting jersey…
Wonjoo Lee
  • 99
  • 3
  • 8
1
vote
1 answer

Inject one bean into another with annotations in Guice

I am new to Guice so this might be a basic question. Guice beans get created correctly with below code in Module public class MyModule extends AbstractModule { @Override protected void configure() { ClassA classAObj =…
Sagar
  • 1,149
  • 1
  • 7
  • 12
1
vote
0 answers

How to start Log4j logger during Guice phase1 static binding

I have a Database-JDBC-Connection class and a Setup class that loads the details of the username, password, database host etc and many other properties by reading a configuration file. The database class has a dependency on Setup class and hence I…
palkarrohan
  • 459
  • 1
  • 4
  • 16
1
vote
1 answer

How to call a method in a class after the application has been initalized?

I have classes as below. I want statements in constructor of DataService to be called itself after the application or DataService class has has been initialized and before DataHandler is intitalized. But dataLoader object is null in the…
1
vote
1 answer

How to Inject an object which is created with Assisted Injection in Guice?

I'm trying to pass an object which has a runtime variable into an other object. How can I achieve this using Guice? I'm new to dependency injection. I would like to create several A objects (the number of them is decided at runtime) and that many B…
1
vote
1 answer

How to inject a collection with provider

My application has a class called Gateway and a json file with a set of these gateways. I already parsed this json, giving me a Set object. Now I want to create a Multibinder to inject this set throughout my code. So far, I've created this provider:…
1
vote
1 answer

ServletModule.filter versus @WebFilter

I'm trying to follow a minimal tutorial on using Guice for a web server, without needing a web.xml: http://www.remmelt.com/post/minimal-guice-servlet-without-web-xml/ Like the creator of the tutorial, I cannot manage to make the ServletModule filter…
Kevin
  • 11
  • 2
1 2 3
99
100