Spring 2.0 XML schema-based configuration

翻译 2011年01月08日 11:21:00



原文是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: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"               ------------------工具类
            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 -->














XML Schema-based configuration

XML Schema-based configuration 34.1 Introduction This appendix details the X...

Spring AOP Advices - Before advice example - xml based configuration - See more at: http://www.java2

In Spring, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modular...

Spring AOP Advices - Around advice example - xml based configuration

In Spring, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modular...

Spring AOP Advices - After returning advice example - xml based configuration

In last tutorial, you are able to get the MessageSource via ApplicationContext. But for a bean to ge...

Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace

今天自己整合SSM,总是报如下的错误,怎么也解决不了,最后发现居然是Mybatis的jar包版本低了,而且少了一个jar包。。。 报错用的jar包是替换的jar包为 org.springframe...

Spring Aop实现——Annotation方式(注解式)and Schema-based式(xml配置)

Spring Aop实现——Annotation方式(注解式)and Schema-based式(xml配置) Spring Aop实现——Annotation方式(注解式)一、spring依赖库* ...

spring2.0基于XML Schema的AOP实现以及AOP事务

1. Before Advice和After Adviceimport org.aspectj.lang.JoinPoint;public class LogAdvice { //基于XML Sche...

[Spring]Annotation-based container configuration_AnotationBasis_01

基于注解的容器配置 首先使用注解和xml配置,本质上没有好坏之分,只有适合不适合之分。如果你觉得哪个顺手就用哪个,或者都用。 首先要使用anotation-config 需要在xml中配置...

Spring中Aspectj和Schema-based AOP混用引起的错误

  • mydeman
  • mydeman
  • 2011年11月08日 14:32
  • 4914

使用Spring(11)使用Spring进行面向切面编程(AOP)Schema-based AOP support

使用XML格式 官方说明: 在Spring的配置文件中,所有的切面和通知器都必须定义在 元素内部。 一个application context可以包含多个 。 一个 可以包含pointcut,a...
您举报文章:Spring 2.0 XML schema-based configuration