This article covers a Bloomreach Experience Manager version 12. There's an updated version available that covers our most recent release.

Spring Bean Bridge

Since Bloomreach Experience Manager 11, Spring Bean Bridge is deprecated and it is encouraged to use Spring Managed HST Components instead.
Since Bloomreach Experience Manager 7.8.4, HST also supports a different integration approach, Container Level Integration, which might be what you are looking for, see HST Container Integration with Other Web Application Frameworks.

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>
NOTE: The bean example above is scoped to " prototype". SpringBridgeHstComponent instance retrieves the bean only once, invoked #init() method on the bean and keep it as member initially. By scoping the bean as " prototype", you can set multiple HST Component configurations with  SpringBridgeHstComponent bridge class to share one Spring bean definition. If you use " singleton" (default) scoped bean, then you should add a different Spring bean definition per an HST Component configuration using SpringBridgeHstComponent bridge class, in order not to parameters collision between different component configurations.

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).

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?