在 Spring 3 中禁用架构验证
-
08-10-2019 - |
题
我们使用 JOSSO 框架进行单点登录。在 Spring 2.5.6 中可以正常工作。似乎 Spring 3 中引入了严格的 XML 模式验证,JOSSO XSD 已经很长时间没有更新了,因此我们在服务器启动过程中遇到错误。有没有办法在 Spring 3 中禁用架构验证(可能使其工作类似于 2.5.6)..
解决方案
我还没有尝试过,但是 GenericXmlApplicationContext 有一个 setValidating(boolean validating) 方法。
我相信您可以使用此方法来停用验证:
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.setValidating(false);
context.load("myResource.xml", "otherResource.xml");
context.refresh();
https://jira.springframework.org/browse/SPR-5014
如果您在 Web 应用程序中使用 spring,那么设置验证参数会更加困难。我能想到的一种方法是基于 ContextLoader 使用 web.xml 上下文参数的事实“contextClass
" 指定上下文类(默认为: org.springframework.web.context.support.XmlWebApplicationContext
).
- @看:org.springframework.web.context.ContextLoader
- @看:org.springframework.web.context.ContextLoader#defineContextClass(ServletContext)
也许您可以创建禁用验证的 XmlWebApplicationContext 子类并使用“contextClass
" 参数来加载此类而不是 XmlWebApplicationContext。
不隶属于 StackOverflow