Spring Bean Bridge
A Simple Spring Framework managed Bean Integration Example: Contact-Spring
HST-2 Spring Bean Bridge supports simple delegation to a Spring Framework managed HST Component bean.
If you want to see a demo, build and run the demo in Hippo Test Suite project. The example is available in our source repository: Hippo Test Suite.
Next, click on the Contact-Spring link on the left menu of the example website ( http://localhost:8080/site/contact-spring). You will see a page containing a simple form and when you type some invalid information, e.g., wicky as email, the page will show some validation errors which were generated by the delegated component bean. If you fill valid information it will show a success view.
In summary:
-
You need to use SpringBridgeHstComponent for a hst component class with dispatched bean name.
-
You need to configure a bean in a either root web application context or HST Container assembly overriding file (i.e, META-INF/hst-assembly/overrides/*.xml).
The Spring Framework managed bean injection could be used only when the hst component class is defined as org.hippoecm.hst.component.support.spring.SpringBridgeHstComponent.
/contactspringform: jcr:primaryType: hst:component hst:template: contactspring hst:componentclassname: org.hippoecm.hst.component.support.spring.SpringBridgeHstComponent hst:parameternames: [spring-delegated-bean] hst:parametervalues: [contactBean]
So, the real component class must be set as " spring-deletgated-bean" HST component parameter, and so the delegated bean must be found by it. In the example above, a Spring Framework managed bean must be found by the bean name, contactBean, which might be configured like the following example:
<bean id="contactBean" class="org.hippoecm.hst.demo.spring.ContactSpring" scope="prototype"> <property name="mailSender" ref="mailSender" /> <property name="templateMessage" ref="templateMessage" /> </bean>
By the way, the delegating component ( org.hippoecm.hst.component.support.spring.SpringBridgeHstComponent) will look up the bean from either the root web application context or HST Container component manager.
There's an example of this in the HST Test Suite. Navigate to http://localhost:8080/site/contact-spring. In this example, to configure the root web application context, some spring configurations are set with /WEB-INF/applicationContext.xml, which has the delegated bean ( id= contactBean) with some dependency configurations. Please have a look at that example. (Please note that you can also define the delegated bean in an HST Container assembly overriding file (i.e, META-INF/hst-assembly/overrides/*.xml).