The simplest XML file header explain the namespace header parsing mode content
While the XML configuration of spring is rather cumbersome, it is not as easy to recommend the annotated approach, but it is important to be able to read XML configuration files, especially for the maintenance of some old systems, almost inevitably facing the problem of XML configuration files. Now let's start with the default XML file header. Most concise XML file Headers
This is the most concise spring file header, but it still looks a lot, dazzling. In fact, careful analysis, it will feel that there are not many things in fact.
<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns=
"Http://www.springframework.org/schema/beans"
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xmlns:context= "http://www.springframework.org/ Schema/context "
xsi:schemalocation=" Http://www.springframework.org/schema/beans
http:// Www.springframework.org/schema/beans/spring-beans.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context.xsd ">
<context:component-scan Base-package= "Cn.edu.buaa"/>
</beans>
First, you need to understand some of the knowledge of the XML itself, which has nothing to do with spring. detailed name Space
The concept of namespaces, and C++,java are the same, nothing more than to solve the name of the specific issues of attribution, As if you have Student.class, I also have student.class, specifically with which student.class, as long as the previous package name (equivalent to the namespace), you can know who is the student.
The namespaces of XML are defined as xmlns, which is known as the initials of XML namespace. Syntax: xmlns:[prefix]= "[URL of name]"
Where the URL of name is the full namespace, and prefix is the alias of the namespace. Header parsing xmlns= "Http://www.springframework.org/schema/beans": Declares the default namespace for an XML file, followed by a label that does not use namespaces, all from this namespace; Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance": the introduction of the Xmlschema-instance namespace, and referred to as XSI, is obviously also taken from its initials; xmlns: Context= "Http://www.springframework.org/schema/context": ditto, introduce a context namespace, referred to as the context; the last definition is longer:
xsi:schemalocation= "Http://www.springframework.org/schema/beans
http://www.springframework.org/schema/ Beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/ Schema/context/spring-context.xsd "
First, xsi:schemalocation represents the schemalocation attribute in the Xmlschema-instance (XSI) that has just been introduced, and its role is to match multiple < namespaces, pattern position > pairs, Where the namespace and pattern locations are separated by whitespace characters. So the last definition means that the namespace Http://www.springframework.org/schema/beans is http://www.springframework.org/schema/beans/ Spring-beans.xsd mode, and Http://www.springframework.org/schema/context is using http://www.springframework.org/schema/. Context/spring-context.xsd mode.
If you do not understand, you can go to the Http://www.springframework.org/schema/beans site to see, there are spring-beans-2.0.xsd, spring-beans-2.5.xsd, Spring-beans-3.0.xsd, Spring-beans-3.1.xsd, Spring-beans-4.3.xsd, Spring-beans.xsd and many other patterns, and here is the spring-beans.xsd model, spring-context.xsd the same. <context:component-scan base-package= "CN.EDU.BUAA"/>: See the next section for details. schema Content
What is the use of spring-beans.xsd and spring-context.xsd in particular?
You can go to http://www.springframework.org/schema/beans/spring-beans.xsd to view the content of Spring-beans.xsd, which defines a number of properties, such as <xsd: Element name= "Beans", which means that the <beans> tag can be used in XML. at this point, you can finally use spring's stuff in the XML file.
Almost all of spring's stuff can be found in these definition files. For example, Beans's <xsd:documentation> attributes show us the beans Document description: The default ' Lazy-init ' value; The documentation for the ' Lazy-init ' the ' <bean> ' element. Beans also through <xsd:attribute name= "Default-lazy-init" default= "false" Type= "Xsd:boolean" > Defines a Default-lazy-init property, the type is Boolean, the default value is False, and its document is interpreted as the default ' Lazy-init ' value; See the documentation for the ' Lazy-init ' the ' <bean> ' element., let us know more about the details, as detailed in the bean under the lazy-init. Continue digging, find <xsd:attribute name= "lazy-init" default= "Default" type= "Defaultable-boolean", and finally through its doc:indicates Whether or not the this bean is lazily initialized. If false, it is instantiated on startup by Bean factories that perform eager initialization of singletons. The default is ' false '. The Note:this attribute would is inherited by the child bean definitions. Hence, it needs to is specified per concrete bean Definition., knowing the effect is to set this bean to Sanga, if not, initialize the Bean factory to a single instance at startup, and the settings for this property will not be inherited by quilts, so each child bean needs to setThe values that you need.
At this point, <context:component-scan base-package= "Cn.edu.buaa"/> meaning is not difficult to understand. This is an attribute of the Component-scan under a context namespace. The previous xsi:schemalocation told us that we could find the definition in http://www.springframework.org/schema/context/spring-context.xsd.
So the file content of these patterns is actually equivalent to being a very useful wiki.