Automatic Scanning for Content-Bean Annotated Classes

Configuring Automatic Scanning in Web Applications

To enable automatic scanning for content-bean annotated classes, define a context-param in your web.xml file:

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

When you set the hst-beans-annotated-classes context parameter to a string that begins with classpath:*, Bloomreach Content treats the value as a classpath resource location filter.

In the example above, the system scans all classes under the org/example/ package for the @org.hippoecm.hst.content.beans.Node annotation. All detected content beans are registered with the ObjectConverter. You can access the ObjectConverter through the following code:

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

If you need to obtain an ObjectBeanManager, use the following approach:

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

This method is recommended because the ObjectBeanManager provided by HstRequestContext uses a caching ObjectConverter.

You can specify multiple resource filters by separating them with commas or whitespace. If you generated your project using the archetype from Getting Started and set groupId = org.example, the default packages scanned for beans are:

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

In most cases, you do not need to modify these default settings.

Share Feedback
Page: /build/web-application/automatic-scanning-for-content-bean-annotated-classes
Section: Build
Category *