Here is my client:
class Client {
@Inject(optional=true) Service service;
}
Sometimes that Service isn't needed, and we know that information when the JVM starts (i.e before the binder is run).
How do I make the binding optional? If I don't specify a binding at all it tries to new the Service (and fails because there is no zero-ar...
When using Spring's based XML configuration, it's easy to decorate multiple implementations of the same interface and specify the order. For instance, a logging service wraps a transactional service which wraps the actual service.
How can I achieve the same using the javax.inject annotations?
...
I want to filter all requests to my web application through my "SecurityFilter" which checks that a session variable "authToken" is valid. The problem is that in order to get this token you need to hit the "AuthServlet" which is at /auth.
I need to filter all servlets except the /auth servlet with my "SecurityFilter". How can I do thi...
I have tried to understand dependency injection and not quite gotten it, except I have managed to pick up the understanding that it makes it hard to understand somebody else's code. :'(
Anyway, I'm not sure how to briefly describe my problem but I will try. I am currently the sole coder working on a Java project that's been worked on b...
Assume we have a simple @Configuration:
@Configuration
public class FooBarConfiguration {
@Bean
public Foo createFoo() {
return new FooImpl();
}
@Bean
@Autowired
public Bar createBar(Foo foo) {
return new BarImpl(foo);
}
}
This class can be used with AnnotationConfigApplicationContext to p...
I'm just starting to play around with Google Guice as a dependency injection framework and am attempting to retrofit it to a small to medium size project I recently wrote. I understand the basics of how Guice works, but am a bit vague on some of the approach details. For example:
1) Modules are used to define your bindings, which are ...
I want to learn Guice. I use eclipse.
What to download? What to install? What to do in eclipse to use guice?
Thanks.
...
Hi all,
I've recently studied about Guice in a University course, and have seen the Google I/O video about it. In the video, they claim to use it in every Google project, including Wave, etc. I was wondering - is Guice really that ubiquitous? Is it really a must-know-must-use for programmers in Java? Should I always use it over a factor...
For a rich domain driven design I want to use Guice dependency injection on JPA/Hibernate entity beans. I am looking for a similar solution as the Spring @configurable annotation for non-Spring beans.
Does anybody know of a library? Any code examples?
...
Usual dead code detectors don't seem to find which defined objects in a Guice or Gin module are not needed any more: is there a simple way to detect this?
For example, let's say I defined a Provider method for a type with a certain annotation:
@Provides @Named("string range")
String getStringRange(Request foo) {
return foo.getBarPr...
Hi, I have provider which should inject javax.mail.Session (provider looks it up in env. context of tomcat) as singleton. There is a problem when I use field injection somewhere in code:
java.lang.IllegalArgumentException: Cannot subclass final class class javax.mail.Session
Is there a way to go round this? Only clues that I've found ...
How can I use the profiler from NetBeans 6.8 or 6.9 (choosing 'entire application') with guice enhanced classes?
I am using google guice 2.0 (with warp persist 2.0-20090214) for some classes and wanted to profile those classes. But I cannot see a result for those classes. The only result I can see is for one method 'EnhancedClass.access...
I'm using the Guice servlet module and trying to get just the basic filter and listener running. When I start my servlet container I get a java.lang.IllegalAccessException wrapped in an AssertionError.
Basically what appears to be happening is that Guice is trying to instantiate com.google.inject.servlet.ManagedServletPipeline which is...
How does Guice's TypeLiteral overcome the Java generic types erasure procedure?
It works wonders but how is this accomplished?
...
I have a class like so, that I create myself somewhere in my code:
class StarryEyes {
@Inject MyValidator validator;
public StarryEyes(String name) {
//..
}
public doSomething() {
// validator is NULL
}
}
I want Guice to inject an instance of validator, which has a @Singleton annotation.
I have a module th...
I have a class that loads some files into a specific object that itself contains several objects that contain different fields. Exmaple:
class RootItem
{
public SubItemType1 sub1;
}
class SubItemType1
{
public SubItemType2 sub2;
public int data1;
public float data2;
}
class SubItemType2
{
public int data3;
public boolean data4;
}
Al...
Is there a way to create a global guice module? so whenever someone calls the CreateInjector method of the Guice class it will get a specific "global" module?
I am trying to do this because I have a set of compiled classes in a JAR that use the following:
@Inject
MyInterface.dosomething();
and I would like to be able to, in the proje...
I have been trying to use Google Guice in eclipse plug-in development. I have imported Guice jar as another plug-in project. But somehow Guice is unable to inject dependency.
Any ideas???
This is the error message
com.google.inject.ConfigurationException: Guice configuration errors:
1) No implementation for java.util.List<java.lang.S...
My ANT script runs without issue on my linux machine and on some xp VMs. When another engineer tries to kick it off locally, TestNG throws [testng] Caused by: java.lang.ClassNotFoundException: com.google.inject.internal.asm.util.TraceClassVisitor not found in (my libraries are all in here)
I've never seen this class before and don't kno...
I was working with GUice some months ago and now when I return to it, I find I have to reread the Guice documentation and examples to understand what I did with my code.
However, when I look at AspectJ it is all too intuitive. It is an intuitive extension of the Java language. I feel I can sit down and write AspectJ code immediately alr...