SeamFramework.orgCommunity Documentation
Seam provides a method for configuring CDI beans using alternate metadata sources, such as XML configuration. Currently, the XML provider is the only alternative available. Using a "type-safe" XML syntax, it is possible to add new beans, override existing beans, and add extra configuration to existing beans.
Simply include the JAR file and the Seam Solder JAR in your project. For Maven projects, that means adding the following dependencies to your pom.xml:
<dependency>
<groupId>org.jboss.seam.config</groupId>
<artifactId>seam-config-xml</artifactId>
<version>${seam.config.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.seam.solder</groupId>
<artifactId>seam-solder</artifactId>
<version>${weld.extensions.version}</version>
</dependency>
To take advantage of Seam Config, you need metadata sources in the form of XML files. By default these are discovered from the classpath in the following locations:
/META-INF/beans.xml
/META-INF/seam-beans.xml
The beans.xml
file is the preferred way of
configuring beans via XML; however some CDI implementations will not allow this, so
seam-beans.xml
is provided as an alternative.
Here is a simple example. The following class represents a report:
class Report {
String filename;
@Inject
Datasource datasource;
//getters and setters
}
And the following support classes:
interface Datasource {
public Data getData();
}
@SalesQualifier
class SalesDatasource implements Datasource {
public Data getData()
{
//return sales data
}
}
class BillingDatasource implements Datasource {
public Data getData()
{
//return billing data
}
}
The Report
bean is fairly simple. It has a
filename that tells the report engine where to load the
report definition from, and a datasource that provides
the data used to fill the report. We are going to
configure up multiple Report
beans via xml.
Example 1.1.
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="urn:java:ee" xmlns:r="urn:java:org.example.reports"> <r:Report> <s:modifies/> <r:filename>sales.jrxml<r:filename> <r:datasource> <r:SalesQualifier/> </r:datasource> </r:Report> <r:Report filename="billing.jrxml"> <s:replaces/> <r:datasource> <s:Inject/> <s:Exact>org.example.reports.BillingDatasource</s:Exact> </r:datasource> </r:Report> </beans>
The namespace | |
There are now multiple namespaces in the
The namespace | |
The | |
Beans installed using | |
The | |
The | |
This is the shorthand syntax for setting a field value. | |
Beans installed using | |
The | |
The |
The princess rescue example is a sample web app that uses Seam Config. Run it with the following command:
mvn jetty:run
And then navigate to http://localhost:9090/princess-rescue
. The XML configuration for the example
is in src/main/resources/META-INF/seam-beans.xml
.