JBoss.org Community Documentation

9.3. Using JavaBean XML

Together with the bean-deployer XML schema the microcontainer also contains a javabean XML schema. This is a lightweight version of bean-deployer that allows for the construction and configuration of JavaBeans without any advanced features like bean injection, callbacks or dependencies. It is intended to be used in situations where the microcontainer has been customised to remove all of the advanced functionality so that it can be bootstrapped in very small runtime environments.

Construction of POJOs is performed using either a normal constructor or a static factory method. In either case constructor or method parameters can be added as necessary:

Note

JavaBean declarations do not include a name attribute which means that you cannot inject references into other JavaBeans or lookup a reference to a JavaBean instance from a client at runtime.

Once a JavaBean has been constructed then simple injection of property values is possible using the <property> element:


<javabean xmlns="urn:jboss:javabean:2.0" class="org.jboss.test.javabean.support.SimpleBean">
    <property name="ADouble">3.14e12</property>
    <property name="ADate">Jan 01 00:00:00 CET 2001</property>
    <property name="ABigDecimal">12e4</property>
    <property name="ABigInteger">123456</property>
    <property name="abyte">12</property> 
</javabean>

As with properties defined using the bean-deployer XML schema the string values are converted into objects of the correct type using JavaBean PropertyEditors. For cases where the type is ambiguous, e.g. when defining numbers, you can specify the required type by including a class attribute:


<javabean xmlns="urn:jboss:javabean:2.0" class="org.jboss.test.javabean.support.SimpleBean">
    <property name="ANumber" class="java.lang.Long">12345</property> 
</javabean>

Important

Beans created using the bean-deployer XML schema can include JavaBeans created using the javabean XML schema instead of string values. This provides a simple way to inject objects composed of multiple values into a bean property without having to write a complicated property editor:


<bean name="example" class="org.jboss.acme.Example">
    <property name="myProperty">
        <javabean xmlns="urn:jboss:javabean:1.0" class="org.jboss.test.javabean.support.SimpleBean">
            <property name="ADate">Jan 01 00:00:00 CET 2001</property>
            <property name="ABigDecimal">12e4</property>
        </javabean>
    </property>
</bean>