防止在 WebLogic 服务器上对 XSD 进行外部引用

Prevent external reference for XSDs on WebLogic server

我有一个使用 spring-config-messaging-rollup.xml 配置的应用程序。部署到 weblogic 时,日志文件中有以下错误序列:

Stack trace associated with message Error in starting the MDB MyMessageConsumerEJB follows:

java.lang.reflect.InvocationTargetException
...
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 77 in XML document from class path resource [spring-config-messaging-rollup.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 77; columnNumber: 104; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'oxm:jaxb2-marshaller'.
...
10:26:00,050 WARN XmlBeanDefinitionReader - Ignored XML validation warning
org.xml.sax.SAXParseException; lineNumber: 77; columnNumber: 104; schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/oxm/spring-oxm.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
...
Caused by: java.net.ConnectException: Tried all: '2' addresses, but could not connect over HTTP to server: 'www.springframework.org', port: '80'

tl;dr 服务器无法访问互联网,但正在尝试下载 spring-oxm.xsd

有没有办法让服务器使用本地引用来代替这个文件?

我设法解决了这个问题。原来我对 http://www.springframework.org/schema/oxm/spring-oxm.xsd 的引用没有在内部解析,因为从属 spring-oxm jar 中的 spring.schemas 文件指向 xsd 的特定版本。这导致解析器尝试在 Internet 上查找该文件。

根据 spring.schemas 更改我的 spring 配置文件以引用精确版本解决了这个问题。

我正在维护的代码库使用 spring 的过时版本可能会有所帮助 - 较新的实现可能没有同样的问题。