spring 配置文件applicationContext.xml命名空間及標籤解析

以spring-data-elasticsearch-2.0.0RELEASE.jar爲例node

<?xml version="1.0" encoding="UTF-8"?>spring

<beans xmlns="http://www.springframework.org/schema/beans"elasticsearch

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xmlns:context="http://www.springframework.org/schema/context"

   **xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"**

   xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch 

   	http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd

    http://www.springframework.org/schema/context

    http://www.springframework.org/schema/context/spring-context-3.0.xsd

    http://www.springframework.org/schema/beans 

    http://www.springframework.org/schema/beans/spring-beans.xsd">

<!-- 開啓對annonation的支持-->

<context:annotation-config />

<context:component-scan base-package="cn.info.art.core" />

<elasticsearch:transport-client id="client" cluster-nodes="192.168.87.6:9300" cluster-

name="elasticsearch" />spa

<bean name="elasticsearchTemplate"

class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">code

<constructor-arg name="client" ref="client"/>

</bean>

<elasticsearch:repositories base-package="cn.info.art.core.es.repositories"/>

</beans>component

首先找到xml命名空間xml

1: xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearchget

此處標明spring解析誰的命名規則空間it

其次找到spring與elasticsearch的集成jar,spring-data-elasticsearch.jario

找到META-INF,

再找到其下spring.handlers會發現有以下一行

2: http://www.springframework.org/schema/data/elasticsearch=org.springframework.data.elasticsearch.config.ElasticsearchNamespaceHandler

注意1和2的關係,此行表示spring對elasticsearch的集成xml命名空間由此類來實現解析、裝配

以後就是去spring-data-elasticsearch.jar中找到

org.springframework.data.elasticsearch.config.ElasticsearchNamespaceHandler這個類

詳細查看如何對相似<elasticsearch:transport-client這樣的標籤的解析、裝配工做

此分析由馬老闆指導,有理解不足之處,望指正

相關文章
相關標籤/搜索