现象
老项目更换spring版本时,项目启动时报错:
无法读取方案文档 'http://www.springframework.org/schema/tx/spring-tx-4.2.xsd', 原因为 1) 无法找到文档; 2) 无法读取文档; 3) 文档的根元素不是 <xsd:schema>。
原因及解决方式
原因是引入的Spring包和约束文件不匹配。pom文件引入的是 4.2.0.RELEASE 版本的spring-tx,但此版本的jar包中不支持4.2的.xsd文件。
解决方式是打开 spring-tx-4.2.0.RELEASE.jar\META-INF下的 spring.schemas 文件,查看支持的xsd列表,选一个支持的xsd版本配上就ok了。
spring-tx-4.2.0.RELEASE.jar\META-INF下的 spring.schemas 内容如下,确实没有4.2.xsd:
http\://www.springframework.org/schema/tx/spring-tx-2.0.xsd=org/springframework/transaction/config/spring-tx-2.0.xsd
http\://www.springframework.org/schema/tx/spring-tx-2.5.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd
http\://www.springframework.org/schema/tx/spring-tx-3.0.xsd=org/springframework/transaction/config/spring-tx-3.0.xsd
http\://www.springframework.org/schema/tx/spring-tx-3.1.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd
http\://www.springframework.org/schema/tx/spring-tx-3.2.xsd=org/springframework/transaction/config/spring-tx-3.2.xsd
http\://www.springframework.org/schema/tx/spring-tx-4.0.xsd=org/springframework/transaction/config/spring-tx-4.0.xsd
http\://www.springframework.org/schema/tx/spring-tx-4.1.xsd=org/springframework/transaction/config/spring-tx-4.1.xsd
http\://www.springframework.org/schema/tx/spring-tx.xsd=org/springframework/transaction/config/spring-tx-4.1.xsd
将配置文件中的http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
改为http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
后,项目顺利启动。
完结撒花✿✿ヽ(°▽°)ノ✿