I have a Logger Bean that gets injected everywhere I want to log something like this:
@Logger
Log log;
following this blog.
Now I want to also be able to use that logger bean in an unmanaged object. How do I make this object aware that there is a managed logger out there to use?
I’ve read somewhere that using the ApplicationContext is bad practice. But maybe it’s the only way? If so, what would be the best way to do this? This seems like the way to go..?
Thanks!
If you can’t really make the bean managed (by declaring it in
applicationContext.xml),yes, it is one of two ways. In a web application use
WebApplicationContextUtilsto get the application context.Another way is to use
@Configurablewith aspectj weaving, which will make your unmanaged object – managed. But I prefer the first option somehow.