You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

公司网络下Spring XML Schema无重定向访问方法咨询

解决Spring XML Schema重定向被拦截的问题

方法1:直接使用Spring依赖包内置的Schema文件

Spring各模块的依赖包(如spring-beans、spring-context等)中已经内置了对应的XML Schema文件,完全不需要网络请求。你只需修改applicationContext.xml里的schemaLocation,将网络地址替换为类路径格式即可。

比如原本的配置:

xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans.xsd"

修改为:

xsi:schemaLocation="http://www.springframework.org/schema/beans
                    classpath:/org/springframework/beans/factory/xml/spring-beans.xsd"

不同模块的Schema对应类路径不同,比如context模块的spring-context.xsd路径为classpath:/org/springframework/context/config/spring-context.xsd,你可以直接在本地依赖的jar包中找到这些文件的具体位置。

方法2:本地缓存Schema文件并引用

  1. 在可正常访问的网络环境下,从浏览器直接获取原始xsd文件(或从本地Maven仓库的Spring jar包中提取)。
  2. 将下载好的xsd文件放到项目的src/main/resources/schemas目录下。
  3. 修改applicationContext.xml的schemaLocation指向本地文件:
xsi:schemaLocation="http://www.springframework.org/schema/beans
                    classpath:/schemas/spring-beans.xsd"

方法3:Maven项目开启离线模式

如果使用Maven构建,先在正常网络环境下执行mvn clean install,确保本地仓库已下载所有Spring依赖包。之后开启离线模式构建,避免网络请求:

mvn -o clean package

此时构建会直接使用本地依赖包内置的Schema文件,无需访问外部网络。

内容的提问来源于stack exchange,提问作者Gary Greenberg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 19:35:55