java.net.MalformedURLException:未知协议:classpath

Muh*_*nan 6 java spring

我试图在spring中使用schemalocation classpath从本地驱动器导入xsd架构.我在类路径中添加了所需的文件,并添加了此文件的引用

15:10:19.336 [localhost-startStop-1] DEBUG o.s.b.f.xml.ResourceEntityResolver - Could not resolve XML entity [classpath:spring-social-facebook-1.1.xsd] against system root URL
java.net.MalformedURLException: unknown protocol: classpath
    at java.net.URL.<init>(Unknown Source) ~[na:1.8.0_31]
    at java.net.URL.<init>(Unknown Source) ~[na:1.8.0_31]
    at java.net.URL.<init>(Unknown Source) ~[na:1.8.0_31]
Run Code Online (Sandbox Code Playgroud)

这是我的applicationContext.xml的标题,

<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"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:beans="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"     xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:social="http://www.springframework.org/schema/social"
    xmlns:facebook="http://www.springframework.org/schema/social/facebook"
    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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.7.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/social http://www.springframework.org/schema/social/spring-social.xsd
            http://www.springframework.org/schema/social/facebook classpath:spring-social-facebook-1.1.xsd">
Run Code Online (Sandbox Code Playgroud)

我使用的是Spring 4.1和spring-bean 3.0版.

M. *_*num 2

您不应该搞乱其他位置并使用默认值。对于 Spring Social Facebook,您应该使用http://www.springframework.org/schema/social/spring-social-facebook-1.1.xsd或最好使用少一的版本http://www.springframework.org/schema/social/spring-social-facebook.xsd

Spring 总是首先从类路径的 jar 中加载 xsd。Spring 附带了一个自定义的EntityResolver,它PluggableSchemaResolver使用 Spring jar 文件目录中的不同spring.schemas文件META-INF

出现像您这样的错误的唯一原因(以及您尝试解决它的原因)是

  1. 您还没有包含 spring-social-facebook 所需的依赖项
  2. 您包含了错误的 spring-social-facebook 依赖项
  3. 您正在使用不兼容的 Spring 和 Spring Social 版本。

我敢打赌选项 2 没有 spring-social-facebook 的所有 1.1.0 版本,而是混合版本的 jars。