
Originally Posted by
nate
Decoupling objects from the container is a noble design goal, but you can't have your cake and eat it, too. The name "ApplicationContextAware" kind of spells out exactly what you're looking for, and it's fairly common to have several application context aware beans in an application. All controllers descended from Spring's abstract controllers implement it, for example.
I'm sure I'm making a mountain out of a molehill here but how I will implement this concept to get my needed results is, unfortunately, still confusing to me.
What I am used to doing to satisfy my above need of sharing an Object across an Application is the following...
This code would be in a WebContextListener that 'sets up' my environment.
Code:
StatusAC status = new StatusAC("All good");
request.getSession().getServletContext().setAtttibute( "statusAC", status );
This code would be in the controllers that need to read the stauts (or update it)
Code:
// Any code needing to read or update the bean does this.
(StatusAC) ac = (StatusAC) request.getSession().getServletContext().getAttribute( "statusAC" );
Now from what I read implementing the ApplicationContextAware would allow me to have knowledge of where the given controller is being run but in the web sense I have this 'built-in' as "All controllers descended from Spring's abstract controllers implement it".
How can I 'springify' the above "WebContextLIster / getServletContext().get/setAttributes() methodology of doing things?
From what I'm reading I think the WebContextAware is not actually what I"m looking for (But I could be wrong).
Thanks for your patience (very new to this).