mattj65816
Dec 20th, 2004, 08:12 PM
Hello. I am very new to Spring and AOP in general. I am writing a web application for which I have created several services. For one of these services, I would like to be able to (optionally) initialize some properties using items from the ServletContext.
It appears that the best way to get the ServletContext during initialization is for the object in question to implement ApplicationContextAware. I do not want to do that directly in the service class because I do not want to couple it to any Spring classes at all. Because of that, I have attempted--I believe successfully--to use Spring AOP to introduce the ApplicationContextAware interface to the service instance. When I iterate over the resulting proxy's interfaces, ApplicationContextAware IS listed.
Problem is, ApplicationContextAware.setApplicationContext() is never invoked on this object. I assume that I am running into an initialization ordering problem here (maybe the proxy is created AFTER the postprocessor does its magic on the application context beans?)
Is it possible to do this? Inject ApplicationContextAware into an object in the web application context XML file and have it catch a setApplicationContext() call? If not, is there any other loosely-coupled way for me to get the ServletContext to the service bean during the initialization process?
Thanks in advance to anyone who can help. I also apologize in advance if this is covered elsewhere. I have been looking for several hours and have been unsuccessful...but that doesn't guarantee that I didn't just look in the wrong places. :-)
It appears that the best way to get the ServletContext during initialization is for the object in question to implement ApplicationContextAware. I do not want to do that directly in the service class because I do not want to couple it to any Spring classes at all. Because of that, I have attempted--I believe successfully--to use Spring AOP to introduce the ApplicationContextAware interface to the service instance. When I iterate over the resulting proxy's interfaces, ApplicationContextAware IS listed.
Problem is, ApplicationContextAware.setApplicationContext() is never invoked on this object. I assume that I am running into an initialization ordering problem here (maybe the proxy is created AFTER the postprocessor does its magic on the application context beans?)
Is it possible to do this? Inject ApplicationContextAware into an object in the web application context XML file and have it catch a setApplicationContext() call? If not, is there any other loosely-coupled way for me to get the ServletContext to the service bean during the initialization process?
Thanks in advance to anyone who can help. I also apologize in advance if this is covered elsewhere. I have been looking for several hours and have been unsuccessful...but that doesn't guarantee that I didn't just look in the wrong places. :-)