Comment by [email protected]:
I spent a couple of days trying to figure out why base classes were not
getting injected with their loggers before I found a solution. Fix up your
Log4JTypeListener's hear() method to look deeper for Logger fields:
{{{
public <T> void hear(TypeLiteral<T> typeLiteral, TypeEncounter<T>
typeEncounter)
{
for (Class<?> c = typeLiteral.getRawType(); c != Object.class; c =
c.getSuperclass())
{
for (Field field : c.getDeclaredFields())
{
if (field.getType() == Logger.class
&& field.isAnnotationPresent(InjectLogger.class))
{
typeEncounter.register(new
Log4JMembersInjector<T>(field));
}
}
}
}
}}}
Also, here is InjectorLogger.java, which is missing from this wiki page:
{{{
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD })
public @interface InjectLogger
{
}
}}}
Cheers, and enjoy!
Oh, it also doesn't inject static members, but that has another solution,
one that I didn't need.
For more information:
http://code.google.com/p/google-guice/wiki/CustomInjections
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.