Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 5
Next, you must provide a bean definition parser to the Spring container to handle the parsing of bean configuration data for each top-level element defined in the component's XSD file.
Again, Spring provides a number of convenience classes that handle much of the default processing for a simple component definition.
The AbstractSimpleBeanDefinitionParser is a convenience class to use when there is a one-to-one mapping between the component class properties and attributes of
the element to be parsed. Given that this is true of our component I can use the simple bean definition parser as shown in
Listing 4.
private static class FoobarBeanDefinitionParser
extends org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser
{
protected Class getBeanClass(Element element)
{
return Foobar.class;
}
}
With a simple component such as the one defined in this article, the only requirement for a subclass of AbstractSimpleBeanDefinitionParser is to return the class that defines the actual implementation of the component; in this case, the Foobar class.
With the component defined and implemented and the namespace handler and parser is in place, you're ready to give the Spring framework the information it needs to consume the component. This is accomplished by registering the namespace handler and XSD file with Spring using two specialized properties files:
Foobar component this is defined as:
http\://www.jeffhanson.com/schema/service/foobar=com.jeffhanson.spring.beans.
FoobarNamespaceHandler
Foobar component, this file contains:
http\://www.jeffhanson.com/schema/service/foobar/foobar.xsd=com/jeffhanson/
spring/beans/foobar.xsd
The two files are to be located in the META-INF directory of the .jar file that will contain the component.
With the bean logic, namespace handler, bean definition parser, and deployment-descriptor properties files in place, you are at the last step in developing a Spring component: compiling and packaging the component for distribution.
DefaultBeanDefinitionDocumentReader for handling custom namespaces in a Spring XML configuration file.
Archived Discussions (Read only)