Using Spring Root WebApplicationContext in HST
This page explains how to configure a Spring Root WebApplicationContext in an HST site web application and enable access to HST Spring Component beans.
Default Spring Root WebApplicationContext Setup
By default, to initialize a Spring Root WebApplicationContext, add the following listener to your web.xml:
<!-- Bootstrap listener to start up root web application context. --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
Enabling Access to HST Spring Component Beans
To allow your Spring Root WebApplicationContext to access beans from the HST Spring Component Manager, you must use HstDelayedContextLoaderListener instead of ContextLoaderListener. Place HstDelayedContextLoaderListener after HstContextLoaderListener in your web.xml:
<!-- HstContextLoaderListener configuring/initializing/destroying HST Container --> <listener> <listener-class>org.hippoecm.hst.site.container.HstContextLoaderListener</listener-class> </listener> <!-- Bootstrap listener to start up root web application context. --> <listener> <listener-class>org.hippoecm.hst.site.container.HstDelayedContextLoaderListener</listener-class> </listener>
HstDelayedContextLoaderListener delays the initialization of the Spring Root WebApplicationContext until the HST Spring Component Manager is available. Starting with version 12.2, the HST Spring Component Manager initializes only after the repository becomes available. This change requires the use of HstDelayedContextLoaderListener to ensure correct bean access.
Note: Use
HstDelayedContextLoaderListenerinstead ofContextLoaderListenerif you need to access HST Spring Component Manager beans from the Spring RootWebApplicationContext.
Configuration Restrictions
When using HstDelayedContextLoaderListener, do not configure the following context parameter in your site's web.xml:
<context-param>
<param-name>hst-lazy-configuration-loading</param-name>
<param-value>true</param-value>
</context-param>
This configuration is not supported with HstDelayedContextLoaderListener.
For additional details, see the PingFilter documentation.