Open Source, Open Future!
  menu
107 文章
ღゝ◡╹)ノ❤️

spring---xml文件

示例

<?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"

       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <context:annotation-config/>

    <bean id="user" class="mncode.User"/>

</beans>

说明

  • 1、<?xml version="1.0" encoding="UTF-8"?>
    文档声明,这是个xml,版本:1.0,编码:UTF-8

  • 2、xmlns="http://www.springframework.org/schema/beans"
    xmlns:全称XML NameSpace(xml命名空间);
    文档的默认命名空间值为:http://www.springframework.org/schema/beans

  • 3、xmlns:context="http://www.springframework.org/schema/context"
    声明一个前缀为context的命名空间,值为http://www.springframework.org/schema/context

  • 4、xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    表示遵守w3的xml schema规范;解析器在解析xml文件时,就会按照这种规范解析。

  • 5、xsi:schemaLocation
    定义了命名空间与xsd文档的映射;用于智能提示和文档校检等;可使用多个键值对,中间用空格或换行隔开。

流程

image.png

通过前缀1找到命名空间2,再找到对应的xsd文件3;
bean标签没有前缀,所以用的是默认的命名空间,对应的xsd文件:http://www.springframework.org/schema/beans/spring-beans.xsd
打开文件,部分内容如下:
image.png
里面定义了能够使用的所有元素。