外部命名空间标签的执行流程,如下:
-
将自定义标签的约束与物理约束文件与网络约束名称的约束,以键值对形式存储到一个spring.schemas文件中,该文件存储在类加载路径的META-INF里,Spring会自动加载到
-
将自定义命名空间的名称与自定义命名空间的处理器映射关系,以键值对形式存在到一个叫spring.handlers文件里,该文件存储在类加载路径的META-INF里,Spring会自动加载到
-
准备好NamespaceHandler,如果命名空间只有一个标签,那么直接在parse方法中进行解析即可,一般解析结果就是注册该标签对应的BeanDefinition,如果命名空间里有多个标签,那么可以在init方法中为每个标签都注册一个BeanDefinitionparser,在执行NamespaceHandle的parse方法时分流给不同的BeanDefinitionPaser进行解析
<?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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd">
<!-- 加载properties文件 --><context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${jdbc.driver}"></property><property name="url" value="${jdbc.url}"></property><property name="username" value="${jdbc.username}"></property><property name="password" value="${jdbc.password}"></property></bean>
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///book?useSSL=false&useServerPrepStmts=true
jdbc.username=root
jdbc.password=1234