最初我的 appcontext.xml header 如下。
<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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd">
如果没有互联网连接,这将不起作用。因此将上面的 xsi:schemaLocation 更改如下
xsi:schemaLocation="http://www.springframework.org/schema/beans
classpath:/org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
classpath:/org/springframework/context/config/spring-context-3.1.xsd
http://www.springframework.org/schema/util
classpath:/org/springframework/beans/factory/xml/spring-util-3.1.xsd"
上述方法需要很长时间来加载 xsd 文件并运行应用程序。
有没有其他方法可以最大限度地减少加载时间。我发现 classpath:/.. 是没有互联网连接时加载 xsd 的唯一选项。有人可以帮我解决这个问题吗?
最佳答案
有关 schemaLocation
的更多信息可在此处找到:
- http://www.w3.org/TR/xmlschema-1/#xsi_schemaLocation
- http://www.w3.org/TR/xmlschema-0/#schemaLocation
如果您使用 Eclipse 中安装的 Spring IDE,则该 IDE 已经拥有您提供的 xmlns
所需的 XSD 副本。因此,它不需要通过 schemaLocation
中提供的 URL 进行查找。
关于java - 在没有互联网的情况下,需要更多时间从类路径加载 spring-*.xsd 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13192713/