Spring 2.0 XML schema-based configuration

來源:互聯網
上載者:User

摘自:http://static.springsource.org/spring/docs/2.5.x/reference/xsd-config.html

 

原文是spring framework reference的附錄A,介紹XML基於模式的配置

 

The central motivation for moving to XML Schema based configuration files was
to make Spring XML configuration easier. The 'classic'

<bean/>
-based approach is good, but its generic-nature comes
with a price in terms of configuration overhead.

From the Spring IoC containers point-of-view, everything

is a bean. That's great news for the Spring IoC container, because if everything is
a bean then everything can be treated in the exact same fashion. The same, however,
is not true from a developer's point-of-view. The objects defined in a Spring
XML configuration file are not all generic, vanilla beans. Usually, each bean requires
some degree of specific configuration.

Spring 2.0's new XML Schema-based configuration addresses this issue.
The <bean/>
element is still present, and if you
wanted to, you could continue to write the exact same

style of Spring XML configuration using only <bean/>
elements. The new XML Schema-based configuration does, however, make
Spring XML configuration files substantially clearer to read. In addition, it allows
you to express the intent of a bean definition.

The key thing to remember is that the new custom tags work best for infrastructure
or integration beans: for example, AOP, collections, transactions, integration with
3rd-party frameworks such as Mule, etc., while the existing bean tags are best suited to
application-specific beans, such as DAOs, service layer objects, validators, etc.

 

一些常用的基於模式的命名空間標籤:

 

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"                   -----------------參見http://blog.springsource.com/2006/11/25/xml-syntax-sugar-in-spring-20/

    xmlns:context="http://www.springframework.org/schema/context"  -----------------context schema中的property-placeholder,用於設定PropertyPlaceholderConfigurer

    xmlns:aop="http://www.springframework.org/schema/aop"            -----------------AOP
    xmlns:tx="http://www.springframework.org/schema/tx"                   -----------------交易管理

    xmlns:util="http://www.springframework.org/schema/util"               ------------------工具類
    xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<!-- <bean/> definitions here -->

</bean>

 

 

 

 

 

 

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.