附录B.Extensible XML authoring
附录 B. Extensible XML authoring
目录
- B.1. Introduction
- B.2. Authoring the schema
- B.3. Coding a
NamespaceHandler
- B.4. Coding a
BeanDefinitionParser
- B.5. Registering the handler and the schema
- B.5.1.
META-INF/spring.handlers
- B.5.2.
META-INF/spring.schemas
- B.5.1.
B.1. Introduction
Since version 2.0, Spring has featured a mechanism for schema-based extensions to the basic Spring XML format for defining and configuring beans. This section is devoted to detailing how you would go about writing your own custom XML bean definition parsers and integrating such parsers into the Spring IoC container.
To facilitate the authoring configuration files using a schema-aware XML editor, Spring's extensible XML configuration mechanism is based on XML Schema. If you are not familiar with Spring's current XML configuration extensions that come with the standard Spring distribution, please first read the appendix entitled 附录 A, XML Schema-based configuration.
Creating new XML configuration extensions can be done by following a (relatively) simple process of authoring an XML schema, coding a NamespaceHandler
implementation, coding one or more BeanDefinitionParser
instances and registering the NamespaceHandler
and the schema in a dedicated properties file. What follows is a description of each of these steps. In the example, we'll create a XML extension (a custom XML element) that allows us to configure objects of type SimpleDateFormat
directly in a Spring IoC container.