Spring self log 00 (Analysis of Spring configuration file header and xsd file version)

From the blog technology

A, Spring configuration file header

Initially declared the head of the Spring configuration file as follows:

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"  
"http://www.springframework.org/dtd/spring-beans-4.3.dtd">  
<beans>  
  
</beans>

1, first line indicates the xml declaration, any well-formed xml documents must be the first line of the statement. This is the equivalent of telling the parser xml document, you give me a xml parser.
2, dtd statement that in the xml elements and attributes, subject to spring-beans-2.0.xsd the document type definition standard.
3, DTD: Document Type Definition file (Document Type Definition) or more can be viewed as a template XML file, where you can define the elements of the XML file, element attributes, the arrangement of elements, and the like contained in the content element Wait.
Because some of the limitations of the DTD, and XML Schema support for data types and namespaces. XML Schema DTD soon replaced
by XML Spring configuration after replace Schema:

<?xml version="1.0" encoding="UTF-8"?>
<beans
        xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
        
</beans>

XML Schema space action:
1, to avoid naming conflicts, and the package is similar to Java
2, the effect of different label categories (like tx namespace in Spring for transaction class label, context namespace for the Label component)

Code explanation:
1, xmlns = "http://www.springframework.org/schema/beans"
declare a default namespace xml file, are not used by default for all other tags namespace namespace.

2, xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance "
declaration XML Schema instance schemaLocation attribute declaration can be used after the
3, xmlns: aop = "http : //www.springframework .org / schema / aop "
declared aop namespace prefix, followed by the URL address used to identify the namespace parser will not be used to find information. Its only effect is to give the namespace a unique name. When a namespace is defined in the start tag of an element, all child elements are the same with the same prefix associated with a namespace.

4, xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
this name can be seen from the ballpark, this position specifying Schema namespace attribute must be used in combination. this property has two values, the first value represents a namespace to use. the second value indicates the position of the XML schema namespace for use

So we need what kind of label on the introduction of what namespace and Schema definitions can be.
Two, there is no version number XSD distinction
Typically, namespace URI corresponding to an address stored XSD

<?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"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
       http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-4.2.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-4.2.xsd">
</beans>

schemaLocation xml namespace provides a mapping to a corresponding XSD file, so we can see, in xsi: schemaLocation string arranged in pairs behind, in front of the namespace of the URI, followed by the URI xsd file.
Spring is the default when you start to load the XSD file to validate xml file, so if sometimes off the network, or some open source software switched domain name, then it is easy to run applications not start. Once Oracle acquisition of Sun Microsystems, encountered this situation. To prevent this, Spring provides a mechanism to load the XSD file from the local default. Open the spring-context-4.2.0.RELEASE.jar, you can see there are two special files:
Here Insert Picture Description
xsd file versions you can use are inside
spring.handlers
Here Insert Picture Description

To think Spring is the XSD files on a local, and then in spring.schemas was made a mapping priority load XSD file from the local inside.
Spring and very intimate, the old version of the XSD files are all put. This can prevent the escalation of the Spring version, and configuration file or use an older version of the XSD file, and then off the net, the application will not start.
We can also see that in the absence of configuration version number with the current version of the XSD file is:

Conclusion: Do not configure XSD version of the Spring configuration file, because no configuration revision number, take the current default jar in the XSD file, reducing the risks. And this agreement is greater than the configured very elegant way.

Published 20 original articles · won praise 0 · Views 205

Guess you like

Origin blog.csdn.net/qq_43697752/article/details/103565130