This appendix details the use of XML Schema-based configuration in Spring.
The 'classic'
<object/>-based schema is good, but its
generic-nature comes with a price in terms of configuration overhead.
Creating a custom XML Schema-based configuration makes Spring XML
configuration files substantially clearer to read. In addition, it allows
you to express the intent of an object definition.
The key thing to remember is that creating custom schema tags work best for infrastructure or integration objects: for example, AOP, collections, transactions, integration with 3rd-party frameworks, etc., while the existing object tags are best suited to application-specific objects, such as DAOs, service layer objects, etc.
Please note the fact that the XML configuration mechanism is totally customisable and extensible. This means you can write your own domain-specific configuration tags that would better represent your application's domain; the process involved in doing so is covered in the appendix entitled Appendix B, Extensible XML authoring.
As a reminder, you reference the standard objects schema as shown below
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/schema/objects/spring-objects-1.1.xsd">
<!-- <object/> definitions here -->
</objects>![]() | Note |
|---|---|
The |
The above Spring XML configuration fragment is boilerplate that
you can copy and paste (!) and then plug
<object/> definitions into like you have always
done. However, the entire point of using custom schema tags is to make
configuration easier.
The rest of this chapter gives an overview of custom XML Schema based configuration that are included with the release.
The tx tags deal with configuring objects in
Spring's comprehensive support for transactions. These tags are covered
in the chapter entitled Chapter 17, Transaction management.
![]() | Tip |
|---|---|
You are strongly encouraged to look at the
|
In the interest of completeness, to use the tags in the
tx schema, you need to have the following preamble at
the top of your Spring XML configuration file; the emboldened text in
the following snippet references the correct schema so that the tags in
the tx namespace are available to you.
<?xml version="1.0" encoding="UTF-8"?>
<object xmlns="http://www.springframework.net"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx">
<!-- <object/> definitions here -->
</object>![]() | Note |
|---|---|
Often when using the tags in the |
The aop tags deal with configuring all things
AOP in Spring. These tags are comprehensively covered in the chapter
entitled Chapter 13, Aspect Oriented Programming with Spring.NET.
In the interest of completeness, to use the tags in the
aop schema, you need to have the following preamble
at the top of your Spring XML configuration file; the emboldened text in
the following snippet references the correct schema so that the tags in
the aop namespace are available to you.
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop">
<!-- <object/> definitions here -->
</objects>The db tags deal with creating
IDbProvider instances for a given database client
library. The following snippet references the correct schema so that the
tags in the db namespace are available to you. The
tags are comprehensively covered in the chapter entitled Chapter 19, DbProvider.
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:db="http://www.springframework.org/schema/db">
<!-- <object/> definitions here -->
</objects>The remoting tags are for use when you want to
export an existing POCO object as a .NET remoted object or to create a
client side .NET remoting proxy. The tags are comprehensively covered in
the chapter Chapter 25, .NET Remoting
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.org/schema/objects"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:r="http://www.springframework.org/schema/remoting">
<!-- <object/> definitions here -->
</objects>The validation tags are for use when you want
definte IValidator object instances. The tags are
comprehensively covered in the chapter Chapter 12, Validation Framework
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:v="http://www.springframework.org/schema/validation">
<!-- <object/> definitions here -->
</objects>Last but not least we have the tags in the
objects schema. Examples of the various tags in the
objects schema are not shown here because they are
quite comprehensively covered in the section entitled Section 5.3.2, “Dependencies and configuration in detail” (and indeed in that
entire chapter).
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/schema/objects/spring-objects-1.1.xsd">
<object id="foo" class="X.Y.Foo, X">
<property name="name" value="Rick"/>
</object>
</objects>To setup VS.NET to provide intellisence while editing XML file for your custom XML schemas you will need to copy your XSD files to an appropriate VS.NET directory. Refer to the following chapter for details, Chapter 28, Visual Studio.NET Integration
For SharpDevelop, follow the directions on the "Editing XML" product documentation.