First,Spring Header Information
Spring configuration file header information is generally fixed, but each label has its own meaning, XML The namespace format is as follows:
<? 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:cache="http://www.springframework.org/schema/cache"
xmlns:p="http://www.springframework.org/schema/p"
Xmlns:task="http://www.springframework.org/schema/task"
XSI:schemalocation="Http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
Http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd
Http://www.springframework.org/schema/taskhttp://www.springframework.org/schema/task/spring-task-3.1.xsd
Http://www.springframework.org/schema/cachehttp://www.springframework.org/schema/cache/spring-cache-3.1.xsd">
< !-xml Configuration Content -- >
< /beans >
1 , XML Schema namespace Effects:
1 ), avoid naming conflicts, like Java in the Package same
2 ) and categorize the labels of different roles (like Context namespace for the label of the component)
2 , code interpretation:
1 ), xmlns= "Http://www.springframework.org/schema/beans"
Statement XML The default namespace for the file, which represents the default namespace for all labels that do not use other namespaces.
2 ), xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Statement XML Schema instance, you can use it after you declare it schemalocation attributes are
3 ), xmlns:context= "http://www.springframework.org/schema/context"
4),xmlns:cache= "http://www.springframework.org/schema/cache"
5),xmlns:p= "http://www.springframework.org/schema/p"
6), xmlns:task= "http://www.springframework.org/schema/task"
7 ), xmlns:aop= "Http://www.springframework.org/schema/mvc"
the declaration prefix is MVC namespace, followed by the URL the address used to mark the namespace is not used by the parser to find information. Its only function is to give the namespace a unique name. When a namespace is defined in the start tag of an element, all child elements with the same prefix are associated with the same namespace.
8 ), xsi:schemalocation= "
Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
This can be seen from the name of an approximate, specified Schema the location of this property must be used in conjunction with a namespace. This property has two values, and the first value represents the namespace that needs to be used. The second value represents the location of the XML schema for use by the namespace
So what kind of tags do we need when we introduce what namespaces and Schema definition is available.
Second, Spring configuration file Structure
Beans the label can contain 4 x Tags:
<alias> for a defined Bean an alias
<bean> to Spring defined in container Bean Elements
<description> used to describe Spring Context or each Bean element, though he would be Spring container is ignored, but <description> elements can be generated by tools that belong to your Spring Context Document
<import> Import Other Spring Context the definition
The following are specific Bean Tags:
1 , Labels Bean can contain the following elements:
<constructor-arg> to Bean The constructor injects a value or reference, that is, the constructor injection
<description> with Beans in the same way, used to describe Spring Context or each Bean element, though he would be Spring container is ignored, but <description> elements can be generated by tools that belong to your Spring Context Document
<lookup-method> use methods to replace Getter injected, specifying a method that will be replicated in the run to return a specified Bean , i.e. Getter injected
<meta> allow for your Bean make Meta configuration, only useful in some special situations
<property> to be Bean To inject a value or reference into a particular property, which is what we always say. Setter injected
<replaced-method> A new implementation to replace a bean 's method
2 , Labels Bean can contain the following properties:
Spring configuration file parsing