0

I have recently migrated code from spring 4 (4.1.7) to spring 5(5.1.4).

During this spring migration I have removed version numbers from project spring Xmls and this is xml schema from library i cannot update:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd"
    default-lazy-init="true"
    >

After upgrade getting below Exception while loading bean definitions due to library XML I have given above:

Caused by: org.xml.sax.SAXParseException; lineNumber: XX; columnNumber: XX; : XML-24500: (Error) Can not build schema 'http://www.springframework.org/schema/context' located at 'http://www.springframework.org/schema/context/spring-context-3.1.xsd'

Detailed stack trace is :

Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 16 in XML document from class path resource [xxxlib-core-spring-main.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 5; <Line 16, Column 5>: XML-24500: (Error) Can not build schema 'http://www.springframework.org/schema/context' located at 'http://www.springframework.org/schema/context/spring-context-3.1.xsd'
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:404)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:257)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:128)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:622)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:518)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:95)
    at com.xxxxxxxx.dataaccess.xxx.util.SpringHelper.init(SpringHelper.java:41)
    at com.xxxxxxxx.dataaccess.xxx.util.SpringHelper.getBean(SpringHelper.java:69)
    at com.xxxxxxxx.dataaccess.xxx.api.xxxAPILoader.<clinit>(xxxAPILoader.java:339)
    ... 30 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 5; <Line 16, Column 5>: XML-24500: (Error) Can not build schema 'http://www.springframework.org/schema/context' located at 'http://www.springframework.org/schema/context/spring-context-3.1.xsd'
    at oracle.xml.parser.v2.XMLError.flushErrorHandler(XMLError.java:428)
    at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:290)
    at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:425)
    at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:242)
    at oracle.xml.jaxp.JXDocumentBuilder.parse(JXDocumentBuilder.java:175)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:77)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:434)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
    ... 46 more
Caused by: oracle.xml.parser.schema.XSDException: Duplicated definition for: 'identifiedType'
    at oracle.xml.parser.schema.XSDBuilder.buildSchema(XSDBuilder.java:1122)
    at oracle.xml.parser.schema.XSDBuilder.build(XSDBuilder.java:673)
    at oracle.xml.parser.schema.XSDValidator.processSchemaLocation(XSDValidator.java:1063)
    at oracle.xml.parser.schema.XSDValidator.startElement(XSDValidator.java:668)
    at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1635)
    at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:458)
    at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:404)
  1. Does it mean we can move to Spring 5 only if all of our libraries are also on spring 5 ? (I can't believe spring can introduce such problem)
  2. Is there any workaround available for this problem ?
  3. Am I missing some configuration due to this getting this Exception

I have come across github-issue which suggests in spring 5 version is dropped but old versions are still supported.

Edit1:

I came across another question: , since I am also using xmlparserv2-12.1.0.2.jar after using below workaround (looks like) it seems to pass this exception (XSDException: Duplicated definition for: 'identifiedType') but still not able to load bean from library, now it throws Exception org.springframework.beans.factory.NoSuchBeanDefinitionException

-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

Edit2:

Above Edit1 solves my problem, bean exception was my local setup problem. I came across another good answer, it says we can not mix unversioned and versioned schemas. But in my case I can not remove version number from third party library, in this case I will have to go through solution given in Edit1, although that looks bad hack.

Is there any other better way to fix this problem ?

Vipin
  • 4,851
  • 3
  • 35
  • 65
  • Old xsd should still be supported, however if you have libraries still on older versions of Spring the migration won't work. Classes have been removed, replaced, moved, renamed and support for frameworks has dropped. So if you use a library that depends on an older version of Spring, you probably run into issues that that library is using older classes not present anymore. On a different note, that `SpringHelper` in there is really scary, generally you shouldn't be doing things like that. – M. Deinum Dec 11 '19 at 09:35
  • Fortunately not getting compilation error in any library so safe there, atleast good to migrate. – Vipin Dec 11 '19 at 09:41
  • Doesn't have to be a compilation error (with a library I assume a dependency in your pom) but an error at runtime. Also I would suggest using Spring 5.1.12 (as that is the most recent 5.1 version). Looking at the stacktrace apparently the xsd validator thinks that there are duplicate elements in the XSD. – M. Deinum Dec 11 '19 at 09:45
  • Thanks, will use 5.1.12 after fixing this problem. IMHO we can stop upgrading because something may get failed at runtime, we can test this to make sure nothing fails at runtime. – Vipin Dec 11 '19 at 09:48
  • Just upgrade to 5.1.12, I wonder why you even choose 5.1.4 instead of the most recent in the 5.1 range? I generally upgrade to the latest version in the range instead of some old release. The issue mentions validation issues and that you should upgrade/fix your xml then. Apparently you are using outdated attributes/things in your XML that aren't supported anymore. I strongly suggest to use the version-less schema variant as that has been the suggested way since 4.x. – M. Deinum Dec 11 '19 at 09:50
  • It will take some time to get these libraries, need to follow process :) And I can not edit xml since this is a library I can not edit. – Vipin Dec 11 '19 at 10:02
  • I suggest to do partial updated, first to latest 4.1, then latest 4.2, 4.3, 5.0 and 5.1. Then you can fix issues slowly and steady. You are now upgrading to a 4 version newer edition with a lot of changes. Hard to tell which version broke things. – M. Deinum Dec 11 '19 at 10:05

0 Answers0