Usage of RegistrarBean

You may create a bean which implements the RegistrarBean interfaces. For all beans that implement this interface, subkernels are created. You can access this new kernel within an instance of RegistrarBean class as register(Kernel) and unregister(Kernel) methods are called once the RegistrarBean instance is created or destroyed.

There is also an interface named RegistrarBeanWithDefaultBeanClass. This interface is very useful if you want or need to create a bean which would allow you to configure many subbeans which will have the same class but different names and you do not know names of those beans before configuration will be set. All you need to do is to implement this interface and in method getDefaultBeanClass() return class which should be used for all subbeans defined in configuration for which there will be no class configured.

As an example of such use case is dataSource bean, which allows administrator to easily configure many data sources without passing their class names, ie.

dataSource {
    default () { .... }
    domain1 () { .... }
    domain2 () { .... }

With this config we just defined 3 beans named default, domain1 and domain2. All of those beans will be instances of a class returned by a getDefaultBeanClass() method of dataSource bean.