setServletContext

Invoked after population of normal bean properties but before an init
callback like InitializingBean's afterPropertiesSet or a
custom init-method. Invoked after ApplicationContextAware's
setApplicationContext.

getWebApplicationContext

NOTE: Only use this if you actually need to access
WebApplicationContext-specific functionality. Preferably use
getApplicationContext() or getServletContext()
else, to be able to run in non-WebApplicationContext environments as well.

Throws:

java.lang.IllegalStateException - if not running in a WebApplicationContext