A good memory is better than a bad pen. 88-spring3 Study (9) Interpretation and explanation of-schema configuration

Source: Internet
Author: User

SPRING1 uses the DTD format, Spring2 later uses the schema format, using the schema format, supports different types of configuration has its own namespace, so that the configuration file has a better extensibility.

No matter what, are both pros and cons, using the schema format, bean.xml file header declaration will be relatively complex very much, whenever I see these complex things, I feel the head of the complex up.
As the disciple code says, "Kung Fu to the stall pass", these things, in the actual work of repeated reading, hard to learn, always understand and know.

Common Spring Configuration Instructions

A complete Bean.xml file in a simple project

<?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:tx="Http://www.springframework.org/schema/tx"    xmlns:p="http://www.springframework.org/schema/p"    XMLNS:AOP="HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"    Xmlns:task="Http://www.springframework.org/schema/task"    xsi:schemalocation="Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3 .0.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context/spring-co Ntext-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.         0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-3.0.xsd Http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd ">   <bean id="Role1" class="Com.spring.Role"p:name=  "Fan Fangming"p:type="admin" />             <aop:config>        <aop:advisor pointcut="Execution (* *). Facade. * (...)) " advice-ref="Txadvice" /></aop:config>   </Beans>
    • 1. Default namespace

Http://www.springframework.org/schema/beans
It has no space name for the definition of the spring bean;

    • 2. XSi Standard namespace

Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
This namespace specifies the appropriate schema style for each namespace in the document, and is the standard namespace defined by the standard organization;

    • 3. Define your own namespace

xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
AOP is the abbreviation for this namespace
"HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" is the whole process of the namespace, and it must be specified in the middle of XSI naming the corresponding schema file.
This namespace is divided into 2 steps, one defining the name of the namespace (for example, AOP), and then specifying the location of the namespace style document.

    • 4. Namespace corresponding schema file
xsi:schemalocation="http//www.springframework.org/schema/beanshttp//www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp//www.springframework.org/schema/contexthttp//www.springframework.org/schema/context/spring-context-3.0.xsdhttp//www.springframework.org/schema/txhttp//www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp//WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOPhttp//www.springframework.org/schema/aop/spring-aop-3.0.xsdhttp//www.springframework.org/schema/taskhttp//www.springframework.org/schema/task/spring-task.xsd "

5. Default namespace Configuration

id="role1"class="com.spring.Role"
    • 6. AOP namespace Configuration
<aop:config>        <aop:advisor pointcut=”execution(* *..facade.*(..))” advice-ref=”txAdvice” />

Good memory is better than bad writing 88-spring3 study (9) Interpretation and explanation of-schema configuration

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.