I have a web application where i am using spring 3.0 and oracle's XMLTYPE related jar's com.oracle.xdb which in turn depends on com.oracle.xml.xmlparserv2 , iam sure most of you aware of the exception that you get when these jars开发者_运维百科 are used with spring 3.0 as below,
Caused by: oracle.xml.parser.schema.XSDException: Duplicated definition for: 'identifiedType'
there are some suggestions to use a different parser like xerces, but in our case since we use the xdb dependency, it looks like we cannot change it to use another parser other than com.oracle.xml.xmlparserv2, it was working fine with spring 2.5.6 is there any info on when this would be fixed either by spring/oracle?
Instead of modifying xmlparserv2.jar
you can add
-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
Click here to read a post on Oracle's forums talking about the issue.
I have identified that the problem is due to the inhability of xmlparserv2 to appropriately parse the xsi:schemaLocation
attribute.
I have checked that this works:
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
While this produces the eror:
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
The workaround is to remove the use of specific namespaces (such as tx, util..) and replace them by the equivalent definitions using common beans. For example, you can replace <tx:annotation-driven/>
with <bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
Remove /META-INF/services directory from xmlparserv2.jar - it's content registers Oracle's parser.
Step 4 of my answer here explains why it happens and a few approaches to fixing it.
Consistent versioning
schema/beans/spring-beans**-3.1**.xsd schema/jee/spring-jee**-3.1**.xsd schema/mvc/spring-mvc**-3.1**.xsd
etc.The order is important. spring-jee-3.1.xsd before spring-beans-3.1.xsd causes error, because in spring-jee-3.1.xsd file we have an import reference to spring-beans-3.1.xsd
If two schemas have an import to the same XSD, you should import that XSD as well to prevent "duplicated definition" error.
For example: I have three schemas:
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/util/spring-util-4.2.xsd
http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
Now I'm getting an errror, because spring-util and spring-jee have an imports to:
<xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="http://www.springframework.org/schema/beans/spring-beans-4.2.xsd"/>
<xsd:import namespace="http://www.springframework.org/schema/tool" schemaLocation="http://www.springframework.org/schema/tool/spring-tool-4.2.xsd"/>
When spring-tool will be imported manually BEFORE spring-util and spring-jee:
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/tool/spring-tool-4.2.xsd
http://www.springframework.org/schema/util/spring-util-4.2.xsd
http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
the XML configuration will be properly parsed.
Obviously, you should have consistient versions.
Small workaround is to define some part of configuration in other files with described different schemas and import it using:
<import resource="part_of_config.xml"/>
精彩评论