【发布时间】: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 版本。