Using java annotation to inject logger dependency

Viewed 30674

I am using spring with aspect-j annotation support to allow for an @Loggable annotation. This allows automatic logging on a class based on the configuration.

I am wondering if I can somehow use this annotation to expose an slf4j Logger variable into the class for direct use, so that I don't have to do something to the effect of:

Logger logger = LoggerFactory.getLogger(MyClass.class);

It would be nice if the above was implicitly available due to the annotation and I could just go about doing logger.debug("..."); without the declaration. I'm not sure if this is even possible.

7 Answers
Related