升级Spring Framework 5后oxm:jaxb2-marshaller的contextPath属性报错
Spring 5.x升级后oxm:jaxb2-marshaller启动报错修复
问题原因
Spring Framework 5.0对OXM命名空间的XML配置做了调整:
- 原
oxm:jaxb2-marshaller的contextPath属性被移除,改为嵌套子元素配置 - 你的XML配置仍使用Spring 3.2版本的Schema,与Spring 5.0的Schema约束不兼容,导致XML解析时触发校验错误
修复方案
1. 更新XML Schema版本
将beans和oxm的XSD版本升级到对应Spring 5.0的版本,修改xsi:schemaLocation:
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-5.0.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-5.0.xsd"
2. 调整jaxb2-marshaller配置语法
把原contextPath属性替换为<oxm:context-path>子元素:
原错误配置:
<oxm:jaxb2-marshaller id="someMarshaller" contextPath="com.marshallable.jaxb" />
修正后配置:
<oxm:jaxb2-marshaller id="someMarshaller"> <oxm:context-path>com.marshallable.jaxb</oxm:context-path> </oxm:jaxb2-marshaller>
验证
修改完成后,Spring容器启动时会正确解析OXM配置,XML Schema校验通过,Jaxb2Marshaller bean可正常初始化。
内容的提问来源于stack exchange,提问作者Kenny Linsky
相关产品推荐
相关产品推荐

