spring load xml定义没有外部url

时间:2013-02-26 17:46:07

标签: xml spring load definition

在我使用Spring框架的应用程序中,在我的environment.xml顶部,我有通常的

<?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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
">

现在我试图摆脱对这些外部URL的依赖,以防它们出现故障。 有没有办法从某些spring或任何java库加载这些XML定义。如果是,那怎么办?

1 个答案:

答案 0 :(得分:1)

Spring将从本地资源加载模式定义,因为它们包含在spring jar中。在每个jar中,您都会找到一个/META-INF/spring.schemas文件,该URI将URI映射到类路径资源。

引自Spring reference docs

  

名为“spring.schemas”的属性文件包含XML Schema位置(与XML文件中的模式声明一起使用,该模式使用该模式作为'xsi:schemaLocation'属性的一部分)到类路径资源的映射。需要此文件来防止Spring绝对必须使用需要Internet访问权限的默认EntityResolver来检索模式文件。