【问题标题】:java.net.MalformedURLException: unknown protocol: classpathjava.net.MalformedURLException:未知协议:类路径
【发布时间】:2015-08-11 10:17:09
【问题描述】:

我正在尝试在 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。

【问题讨论】:

  • 你为什么还要使用classpath: 作为前缀。它应该是 http://www.springframework.org/schema/social/spring-social-facebook-1.1.xsd 而不是你现在拥有的。由于来自 spring 的自定义解析器,它将从类路径上的 jar 文件加载 xsd(就像它对所有其他 xsd 文件一样!)。
  • 实际上 spring-social-facebook xsd 已从位置 springframework.org/schema/social/… 这就是为什么我要在本地创建 xsd 并使用它的原因。
  • 这并不重要,因为它默认是从包含的 jar 文件中解析出来的,就像 spring 中的其他 xsd 文件一样。如果这不起作用(我建议使用无版本模式),您要么在类路径中缺少 jar,使用了错误的版本(不是 1.1),要么使用了不兼容的 Spring 和 Spring Social 版本。

标签: java spring


【解决方案1】:

您不应该乱用其他位置并使用默认值。对于 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 附带了一个自定义 EntityResolverPluggableSchemaResolver 使用 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,而是混合版本的 jars。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2011-11-22
      • 1970-01-01
      • 1970-01-01
      • 2020-04-20
      • 2019-03-26
      • 2019-03-28
      • 2012-09-03
      • 2016-10-08
      相关资源
      最近更新 更多