--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-guice/-/rphjmZue5wQJ.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
The first one you point to is a “Built-in Binding”. However, I do not see this in the guice-3.0.jar. Also, how do I use it?
The second link on Custom Injections scans for a Logger in each class, so this does not seem to be using AOP.
Here is the class I came up with, below. My problem is that I don’t see how to install the pointcut to intercept a specific method in a class. I can bind it to all methods, but not one method. How can I do that?
public class WhisperModule extends AbstractMurmurModule {
@Override
protected void configure() {
…
bindInterceptor(Matchers.subclassesOf(WhisperTerminal.class), Matchers.any(), new LoggingInterceptor());
}
}
public class LoggingInterceptor implements MethodInterceptor {
private Logger logger;
public LoggingInterceptor() {
PropertyConfigurator.configure("log4j.properties");
logger = Logger.getLogger(LoggingInterceptor.class);
}
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
String header = methodInvocation.getThis().getClass()
+ ":" + methodInvocation.getMethod().getName();
logger.info(header + " invocation");
Object result = null;
try {
result = methodInvocation.proceed();
logger.info(header + " return: " + result);
return result;
} catch (Exception ex) {
logger.error(header, ex);
throw ex;
}
}
}
Thanks,
Rob
I did find the Annotations solution.
What would my own Matcher look like, perhaps using reflection and AspectJ expressions to specify methods? Is there such a duck out there?
Thanks,
Rob