"Deep java EE" Spring configuration file parsing

Source: Internet
Author: User

In the process of reading no matter what the problem, welcome to communicate together

Email:[email protected]

qq:1494713801

First,Spring Header Information

Spring the header information of the configuration file is usually fixed. But each tag has its own meaning. the XML 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"

An alternative to "weight loss" for the XML configuration file is to use the P namespace. When we use the P-namespace. We can bean use attributes (attribute) to describe the property value of the bean in the element.


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 the approximate. Specify the location of the Schema 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 possible.

Second, Spring configuration file Structure

Beans the label can include 4 x Tags:

<alias> for a defined Bean an alias

<bean> to Spring defined in container Bean Elements

<description> used to describe the narrative Spring Context or each of the Bean element. Although he will be ignored by the spring container, the <description> element will be able to generate the spring context that belongs to you through the tool Document

<import> Import Other Spring Context the definition

1. Bean namespace:

1) , Labels Bean can include elements such as the following:

<constructor-arg> to Bean The constructor injects a value or reference, that is, the constructor injection

<description> with Beans the same effect. Used to describe Spring context or every bean element, even though he would have been a spring Container is ignored, but the <description> element can generate a Spring context document that belongs to you through a tool

<lookup-method> Use to replace Getter injection, specifying a method. He will be replicated in execution to return a specified bean, the getter injection

<meta> agree for your Bean make Meta configuration, only practical in some special situations

<property> to be Bean to inject a value or reference into a specific property. This is what we often call setter injection .

<replaced-method> replacing a bean 's method with a new implementation

2) , Labels Bean can include properties such as the following:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmduxntc2mq==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center "width=" 550 "height=" 480 ">

2. Context namespace

1), Context tags:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvdtaxmduxntc2mq==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center "width=" 531 "height=" >

<context:component-scan/> Specific explanations

. Suppose you don't want to configure the bean in an XML file. The ability to add Spring component annotations to our classes allows the Bean's own active load to be implemented simply by reconfiguring the spring scanner <context:component-scan/>.

Then add annotations to the program to load the bean yourself,@Componentare all common forms of spring management components;@Repository,@Serviceand the@Controlleris the@ComponentTo represent more detailed use cases (for example, the persistence layer, the service layer, and the presentation layer, respectively).

In other words, you can use@Componentto annotate your component class, but assume that the@Repository,@Service or@Controllerto annotate them, your class may be better handled by tools or associated with facets.

<context:component-scan> provides two sub-tags:<context:include-filter> and <context:exclude-filter> filters introduced and excluded by each representative.

With <context:component-scan>, there is also a <context:annotation-config/> tag that can be removed at all. Because it has been included in the.

3. AOP namespaces

1), AOP tags

4, Jee Namespace

1), JEE label

Deep Java EE Spring configuration file parsing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.