Apache » Cocoon »

  Cocoon Spring Configurator
      2.1
   homepage

Cocoon Spring Configurator 2.1

Dynamic Registry Support

Dynamic Registries

If you want to develop a managing bean which acts like a registry, you face the problem of how to configure this bean. Usually this bean makes use of some kind of a map which stores the registered beans under some key. If you want to configure this in Spring you have to know which registered beans are available at this point of time. Apart from the amount of configuration you have to type, this approach is not dynamic. Adding new registered beans requires to change the configuration of the managing bean. Especially with the spring-configurator, beans can be added dynamically just by dropping a jar into the class-path. The approach of this configuration style will simply not work in these cases.

The Bean Map

The spring-configurator provides a dynamic bean map just for this purpose. It can either be used as a standalone bean or as a property of another bean. If you want to use it as a standalone bean, you have to specify either the name or the id attribute (like you do with the usual Spring bean definition as well):

<configurator:bean-map id/name="optional" type="the.class.of.the.registered.beans" check-parent="true" strip-prefix="true">

</configurator:bean-map>

This will create a map which contains all registered beans which support/implement the given type.

The key to store the registered beans in the map is the bean name, or if "check-parent" is set to true and the bean name starts with the type followed by either a "." or a "/" then the postfix is used as the key.

TBC