JBoss.org Community Documentation

9.2. Writing deployment descriptors

Deployment descriptors externalize the configuration of POJOs into one or more files that are separate from the source code. This means that changes can be made without having to recompile any classes. The usual way to define a deployment descriptor is using the bean-deployer XML schema whose root element is <deployment>. This is used to group multiple beans together so that they are deployed as a unit:


<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd"
                    xmlns="urn:jboss:bean-deployer:2.0">

    <!-- Bean definitions -->

</deployment>

The bean definitions are created using <bean> elements that each describe a single POJO instance. Each bean is given a name so that it can be referenced elsewhere in the deployment descriptor or looked up by a client at runtime.


<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd"
                    xmlns="urn:jboss:bean-deployer:2.0">

    <bean name="Person" class="org.jboss.example.microcontainer.PersonBean"/>

    <bean name="Address" class="org.jboss.example.microcontainer.AddressBean"/>

</deployment> 

The name of the file containing these elements can be anything you like providing that a deployer can access it and parse the contents correctly. By convention it is called jboss-beans.xml as anything that ends in -beans.xml is found by default using the FileStructure deployer.

Note

Although deployment descriptors are usually created using the bean-deployer XML schema it is also possible to use other XML schemas or even Java properties as shown in the following sections.