SPRING指定加載本地xsd約束

                             哈哈,大家好,我是一名小小程序員,今天開始我也開始寫博客了,~因爲知識取自於互聯網,所有想把自己的一些小經驗寫出來回饋大家,!

 

情景:

<?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:mvc="http://www.springframework.org/schema/mvc"
  xmlns:p="http://www.springframework.org/schema/p"
  xmlns:context="http://www.springframework.org/schema/context"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
           http://code.alibabatech.com/schema/dubbo  
       http://code.alibabatech.com/schema/dubbo/dubbo.xsd"  
  default-autowire="byName">

寫了一個程序打成jar包 倒出來後報錯 dubbo:application  這個約束找不到, 原因是http://code.alibabatech.com/schema/dubbo 約束的網站已經停了,淘寶已經關閉了這個網站,

那麼把dobbo.xsd這個約束下載下來 放到本地如何 讓spring加載本地呢?

   解決方法:

       其實spring是做的很貼心的,他默認是先加載本地的,你打開它的源碼包META-INF 下 會發現2個文件,

spring.handlers  ,spring.schemas  這2個文件

例如spring.schemas 指定這個本地的xsd在哪個目錄下, 

spring.handlers  指定處理這個頭信息的java類是哪個,

 

在spring-core.jar的META-INF下 spring.handlers 加上一行http\://code.alibabatech.com/schema/dubbo=com.alibaba.dubbo.config.spring.schema.DubboNamespaceHandl

在spring.schemas  加上一行http\://code.alibabatech.com/schema/dubbo/dubbo.xsd=META-INF/dubbo.xsd 

成功解決這個問題!

 

QQ 283398689   歡迎來討論!,還求有hadoop方面的高手來加我 多多指導!

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章