现在的位置: 首页 > 综合 > 正文

SPRING指定加载本地xsd约束

2018年12月14日 ⁄ 综合 ⁄ 共 1598字 ⁄ 字号 评论关闭

                             哈哈,大家好,我是一名小小程序员,今天开始我也开始写博客了,~因为知识取自于互联网,所有想把自己的一些小经验写出来回馈大家,!

 

情景:

<?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方面的高手来加我 多多指导!

 

 

 

 

 

抱歉!评论已关闭.