Automatic Scanning for Content-Bean Annotated Classes

How to configure automatic scanning in web applications

In the web.xml, make sure there is a context-param like

<context-param>
  <param-name>hst-beans-annotated-classes</param-name>
  <param-value>classpath*:org/example/**/*.class</param-value>
</context-param>

When the context parameter, " hst-beans-annotated-classes" is set to a string starting with " classpath:*", the parameter values is treated as classpath resource location filters.

So, in the example above, every content bean class, which annotated org.hippoecm.hst.content.beans.Node, will be automatically scanned from the classpath resources under org/example/ package. All these content beans will be available by the ObjectConverter which you can access through:

HstRequestContext ctx = RequestContextProvider.get();
ContentBeansTool cbt = ctx.getContentBeansTool();
ObjectConverter objectConverter = cbt.getObjectConverter;

However note, that if you want to get hold to an ObjectBeanManager you can better use 

HstRequestContext ctx = RequestContextProvider.get();
ObjectBeanManager objectBeanManager = ctx.getObjectBeanManager();

This is preferred because the HstRequestContext comes with an ObjectBeanManager backed by a caching ObjectConverter.

You can also configure multiple resource filters by separating those by comma or white space. When you created your project with the archetype from Getting Started and for example used as groupId = org.example, then by default the packages that will be scanned for beans are as follows and in general do not need any modification:

<context-param>
  <param-name>hst-beans-annotated-classes</param-name>
  <param-value>classpath*:org/onehippo/cms7/hst/**/*.class
      ,classpath*:org/onehippo/**/*.class
      ,classpath*:com/onehippo/**/*.class
      ,classpath*:org/onehippo/forge/**/*.class
  </param-value>
</context-param>

 

 

 

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?