Most of this section is well travelled territory for those familiar
with editing XML files in their favorite XML editor. The XML configuration
data that defines the objects that Spring will manage for you are
validated against the Spring.NET XML Schema at runtime. The location of
the XML configuration data to create an
IApplicationContext can be any of the resource
locations supported by Spring's
abstraction. (See Section 7.1, “Introduction” for more
information.) To create an
using a "standalone" XML configuration file the custom configuration
section in the standard .NET application configuration would read:
<spring> <context> <resource uri="file://objects.xml"/> </context> </spring>The VS.NET 2005 XML editor can use the attribute
xsi:schemaLocationas a hint to associate the physical location of a schema file with the XML document being edited. VS.NET 2002/2003 do not recognize the
xsi:schemaLocationelement. If you reference the Spring.NET XML schema as shown below, you can get intellisense and validation support while editing a Spring configuration file in VS.NET 2005. In order to get this functionality in VS.NET 2002/2003 you will need to register the schema with VS.NET or include the schema as part of your application project.
<?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/xsd/spring-objects.xsd"> <object id="..." type="..."> ... </object> <object id="..." type="..."> ... </object> ... </objects>
It is typically more convenient to install the schema in VS.NET, even for VS.NET 2005, as it makes the xml a little less verbose and you don't need to keep copying the XSD file for each project you create. For VS.NET 2003 the schema directory will be either
C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\Packages\schemas\xml for VS 2003
C:\Program Files\Microsoft Visual Studio
.NET\Common7\Packages\schemas\xml for VS.NET 2002
The VS.NET 2005 directory for XML schemas is
C:\Program Files\Microsoft Visual Studio
Spring's .xsd schemas are located in the directory doc/schema. In
that directory is also a NAnt build file to help copy over the .xsd files
to the appropriate VS.NET locations. To execute this script simply type
nant' in the doc/schema directory.
Once you have registered the schema with VS.NET you can adding only the namespace declaration to the objects element,
<?xml version="1.0" encoding="UTF-8"?> <objects xmlns="http://www.springframework.net"> <object id="..." type="..."> ... </object> <object id="..." type="..."> ... </object> ... </objects>
Once registered, the namespace declaration alone is sufficient to get intellisense and validation of the configuration file from within VS.NET. Alternatively, you can select the .xsd file to use by setting the targetSchema property in the Property Sheet for the configuration file.
As shown in the section Section 5.2.6, “Using the container” Spring.NET supports using .NET's application configuration file as the location to store the object definitions that will be managed by the object factory.
<configuration> <configSections> <sectionGroup name="spring"> <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/> <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" /> </sectionGroup> </configSections> <spring> <context> <resource uri="config://spring/objects"/> </context> <objects xmlns="http://www.springframework.net"> ... </objects> </spring> </configuration>
In this case VS.NET 2002/2003 will still provide you with
intellisense help but you will not be able to fully validate the document
as the entire schema for App.config is not known. To be able to validate
this document one would need to install the .NET
Configuration File schema and an additional schema that
<context> section in addition to the
<objects> would need to be created.
Validating schema is a new feature in VS 2005 it is validating all the time while you edit, you will see any errors that it finds in the Error List window.
Keep these trade offs in mind as you decide where to place the bulk of your configuration information. Conventional wisdom is do quick prototyping with App.config and use another IResource location, file or embedded assembly resource, for serious development.
The schema was updated from Spring 1.0.1 to 1.0.2 in order to
support generics. The schema for version 1.0.1 is located under
http://www.springframework.net/xsd/1.0.1/ The schema
for the latest version will always be located under