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
24
votes
3 answers

How to get all implementors/subclasses of an interface with Guice?

With Spring, you can define an array property and have Spring inject one of every (@Component) class that derives from the given type. Is there an equivalent for this in Guice? Or an extension point to add this behavior?
Adam Vandenberg
  • 19,991
  • 9
  • 54
  • 56
24
votes
4 answers

Guice and general application configuration

For a monitoring software written in Java I consider using Google Guice as DI provider. The project needs to load its configuration from an external resource (file or database). The application is designed to run in standalone mode or in a servlet…
mjn
  • 36,362
  • 28
  • 176
  • 378
24
votes
2 answers

No implementation was bound - Java Guice

Novice here trying to use a dummy Java Facebook app that uses Guice to inject a database dependency into the Facebook factory but continue to have Guice error out telling me: ### No implementation for com.example.storage.Db annotated with…
Lorena Nicole
  • 499
  • 2
  • 9
  • 21
24
votes
5 answers

Spring and Guice together, or just Spring

I'm starting a new Java web app from scratch. I don't have much experience on Spring Framework, but I know I'd like to use some of its features, such as Transaccions Management. On the other hand, I really like Guice for dependency injection. I…
csalazar
  • 748
  • 1
  • 7
  • 13
24
votes
4 answers

How to bind String to variable in Guice?

I'm new to Guice and here is a naive question. I learned that we could bind String to a particular value through: bind(String.class) .annotatedWith(Names.named("JDBC URL")) .toInstance("jdbc:mysql://localhost/pizza"); But what if I…
eric2323223
  • 3,518
  • 8
  • 40
  • 55
24
votes
2 answers

Can Guice inject Scala objects

In Scala, can I use Guice to inject Scala objects? For example, can I inject into s in the following object? object GuiceSpec { @Inject val s: String = null def get() = s }
Hbf
  • 3,074
  • 3
  • 23
  • 32
23
votes
4 answers

Custom Guice Scope, or a better approach?

Here's my problem: It's first important to know that I'm writing a simulation. This is a standalone application, and is single-threaded. I have essentially two classes of objects that have different scoping requirements. Classes that should be…
Josh
  • 2,077
  • 1
  • 17
  • 21
23
votes
4 answers

Does it make sense to use Guice for Android

I'm debating using guice in an android project that is quite complex and has a lot of business logic. Guice seems like a good fit, but whenever I start reading deeper into it, it starts to look more complicated than it needs to be. One thing I…
Otto
  • 1,675
  • 2
  • 19
  • 30
23
votes
1 answer

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

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…
Justinas Jakavonis
  • 8,220
  • 10
  • 69
  • 114
23
votes
2 answers

How to run ScalaTest with Guice DI and Slick?

I don't know how to configure GuiceApplicationBuilder in such a way, that I am able to load controllers that require a DatabaseConfigProvider to be injected. I'd like to specify an alternative postgres database for testing, or an in memory database…
Taig
  • 6,718
  • 4
  • 44
  • 65
23
votes
2 answers

Generic @Inject'd fields in an abstract superclass

Consider a MVP-ish set of types. An abstract Presenter exists, with a View interface: public interface View { //... } public abstract class AbstractPresenter { @Inject V view; //... } Then, lets have a specific concrete…
Colin Alworth
  • 17,801
  • 2
  • 26
  • 39
22
votes
7 answers

Why is HttpServletRequest inputstream empty?

I have this code where I read the input from a request input stream and use a JacksonMapper to convert into a POJO. Its running in a jetty 7 container with guice support. @Override protected void doPost(HttpServletRequest req, HttpServletResponse…
Usman Ismail
  • 17,999
  • 14
  • 83
  • 165
22
votes
3 answers

Alternative to dozer for bean mapping?

I am trying to figure out an easy way to map DTOs to entities without the boiler-plate code. While I was thinking of using dozer it appears to require a lot of xml configuration. Has anybody seen a dozer alternative that uses a DSL to configure…
benstpierre
  • 32,833
  • 51
  • 177
  • 288
21
votes
3 answers

How to use Google Guice to create objects that require parameters?

Maybe I am just blind, but I do not see how to use Guice (just starting with it) to replace the new call in this method: public boolean myMethod(String anInputValue) { Processor proc = new ProcessorImpl(anInputValue); return…
Daniel Schneller
  • 13,728
  • 5
  • 43
  • 72
21
votes
5 answers

Use of TypeLiteral in java

Please provide some basic information of how TypeLiteral in Google Guice or Java EE is used, It will be very helpful if it would be explained using a simple code, thanks in advance
user1119283
  • 397
  • 1
  • 4
  • 12