Java.net.MalformedURLException: 未知协议:classpath。

6

我正在尝试使用spring中的schemalocation类从本地驱动器导入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]

这是我的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">

我正在使用Spring 4.1和Spring Bean版本3.0。


https://dev59.com/Sofca4cB1Zd3GeqPi3O9 - Vartlok
2
你为什么要使用 classpath: 作为前缀呢?应该使用 http://www.springframework.org/schema/social/spring-social-facebook-1.1.xsd,而不是现在的。由于 Spring 中的自定义解析器,它将从类路径中的 jar 文件加载 xsd(以及所有其他 xsd 文件!)。 - M. Deinum
实际上,spring-social-facebook xsd已从位置http://www.springframework.org/schema/social/spring-social-facebook-1.1.xsd中删除,这就是为什么我正在尝试在本地创建xsd并使用它的原因。 - Muhammad Adnan
1
这并不重要,因为它默认从包含的jar文件中解析,就像Spring中的其他xsd文件一样。如果这行不通(我建议使用没有版本号的模式),那么你可能在类路径中缺少jar文件,使用了错误的版本(不是1.1),或者使用不兼容的Spring和Spring Social版本。 - M. Deinum
2个回答

2
您不应该去搞其他位置和使用默认值。对于Spring Social Facebook,您应该使用http://www.springframework.org/schema/social/spring-social-facebook-1.1.xsd或更好的版本less onehttp://www.springframework.org/schema/social/spring-social-facebook.xsd
Spring将总是首先从类路径下的jar加载xsd。Spring附带了一个自定义的EntityResolver,即PluggableSchemaResolver,它使用Spring jar文件的META-INF目录中的不同spring.schemas文件。
您遇到此类错误(以及为什么要尝试解决它)的唯一原因是:
  1. 您没有包含所需的spring-social-facebook依赖项
  2. 您已经包含了错误的spring-social-facebook依赖项
  3. 您正在使用不兼容的Spring和Spring Social版本。
我敢打赌选项2是没有所有1.1.0版本的spring-social-facebook,而是混合了jar的版本。

1

我已解决了问题,因为我使用的是错误的spring-social-web jar包,而不是包含xsd的spring-social-facebook。我不再需要使用类路径了。谢谢M. Deinum


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接