SAXParseException, the root element of the document is not <xsd:schema> - spring

Here is the header of my spring-security.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<b:beans xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/security/oauth2
http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd ">
When starting the server, I am prompted this error :
org.xml.sax.SAXParseException: schema_reference.4: Failed to read
schema document
'http://www.springframework.org/schema/security/spring-security-oauth2-2.0.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/>.
My thoughts on this :
The link is valid and the document exists
I can read it and I can even reproduce this error if I place this xsd on my local classpath. So it's not a networking issue.
That's right, the file is starting by <xs:schema> instead of <xsd:schema>. But the source looks legit.
Why do I get this error and how can I get rid of it ?

Change all your schema locations to use version-less URIs, those XSDs are embedded in Spring JARs.
Because you're using versioned links to XSDs, your application breaks if it can't find that particular version on classpath.
See this SO answer for more details.

Related

Spring Exception: The matching wildcard is strict, but no declaration can be found for element 'int-jpa:inbound-channel-adapter'

I have the following spring-config xml file, which is generating the exception shown in the title of my post:
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jpa="http://www.springframework.org/schema/integration/jpa"
xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp"
xmlns:file="http://www.springframework.org/schema/integration/file"
xmlns:int-xml="http://www.springframework.org/schema/integration/xml"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jpa
http://www.springframework.org/schema/integration/jpa/spring-integration-jpa.xsd
http://www.springframework.org/schema/integration/sftp
http://www.springframework.org/schema/integration/sftp/spring-integration-sftp.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/integration/file
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/integration/xml
http://www.springframework.org/schema/integration/xml/spring-
integration-xml.xsd">
<int-jpa:inbound-channel-adapter
id="resultsProcessor"
channel="responseChannel"
auto-startup="true"
named-query="OpenRecords"
expect-single-result="true"
delete-after-poll="false"
entity-class="foo.Request">
<int:poller
id="responsePoller"
fixed-rate="5000"
max-messages-per-poll="10">
</int:poller>
</int-jpa:inbound-channel-adapter>
</beans>
The code I provide above has other elements removed from it, and some of the fields renamed to simplify the example. That is why you see some schema and namespace information at the top that does not apply to the example as presented.
The error actually takes place at the line corresponding to entity-class="foo.Request">, but I don't know that there is anything inherently wrong with that line, but simply that is where the termination ">" is. In other words, if I removed that line and put the ">" after delete-after-poll="false", the error would be there instead.
Am I perhaps missing a namespace and/or schema location definition? Alternatively, could it be a missing deployment dependency? Grateful for any ideas. Thank you.
Please add org.springframework.integration:spring-integration-jpa to your dependencies. You simply missing a jar in your classpath

schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring- beans-4.1.5.xsd

I get an error in spring-dispatcher.xml in eclipse as given below.
schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-
beans-4.1.5.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>.
I have latest spring libraries...
spring-beans-4.1.5.RELEASE.jar
spring-beans-4.1.5.RELEASE-javadoc.jar
spring-beans-4.1.5.RELEASE-sources.jar
spring-context-4.1.5.RELEASE.jar
spring-context-4.1.5.RELEASE-javadoc.jar
spring-context-4.1.5.RELEASE-sources.jar
spring-context-support-4.1.5.RELEASE.jar
spring-context-support-4.1.5.RELEASE-javadoc.jar
spring-context-support-4.1.5.RELEASE-sources.jar
spring-webmvc-4.1.5.RELEASE.jar
spring-webmvc-4.1.5.RELEASE-javadoc.jar
spring-webmvc-4.1.5.RELEASE-sources.jar
spring-webmvc-portlet-4.1.5.RELEASE.jar
spring-webmvc-portlet-4.1.5.RELEASE-javadoc.jar
spring-webmvc-portlet-4.1.5.RELEASE-sources.jar
spring-dispatcher.xml as given below...
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.5.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
It would be great if I get some help... The posts with same subject did not help me to resolve this.Thanks in advance...
The error is because it could not find the xsd. Try doing the below which is using a specific version 4.1.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
Or if you don't mention a version, it will try to use the latest.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
From Cosmina I. - Pivotal Certified Professional Spring Developer Exam A Study Guide - 2017
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
A recommended (best) practice is to use this, since the version will
be correctly identified from the Spring dependency version in the
project. Also, the other advantage is that you can upgrade the Spring
version you are using, and the new definition specifications will be
automatically supported in your configuration files without your
having to modify them
There is no such xsd in any Spring jar :
http://www.springframework.org/schema/beans/spring-beans-4.1.5.xsd
Spring xsd for Spring 4.1.x can be referenced by :
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
or better :
http://www.springframework.org/schema/beans/spring-beans.xsd
The correspondance between the URL and the real location inside each spring jar can be found in META-INF/spring.schemas, so the "version less" URL will still work when u upgrade Spring.
In my case it went away by adding
<?xml version="1.0" encoding="utf-8"?>
to spring-dispatcher.xml and then running update maven project.
Belive me or not, this may be a maven problem if you're using it and things ended up like this from nothing. I know this may not be your case, but if so, please update your maven project. If you're using Eclipse IDE:
Right click on the project name.
Maven.
Update Project...
Again, this may be your case. It worked for me doing this. This can work also to anybody else who is on the same situation.
Try this, it worked for me
<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"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
I have enroled for spring course on udemy. I followed every step that my instructor show me to do.
So if you are using spring mvc and hibernate you may encounter this error
Failed to read schema document 'http://www.springframework.org/schema/tx/spring-tx.xsd' etc for:
<mvc:annotation-driven/> and <tx:annotation-driven transaction-manager="myTransactionManager" /> elements
in my spring configuration file i had these two urls
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
in xsi:schemaLocation, which i replaced with
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
Actually visit these two sites
http://www.springframework.org/schema/mvc/ and http://www.springframework.org/schema/tx/
and just added the latest version of spring-mvc and spring-tx i.e, spring-mvc-4.2.xsd and spring-tx-4.2.xsd as shown above.
In my opinion specifying version no explicitly is a good practice.
It worked for me, hope this works for you too.
Thank you.
I tried modifying the xml as mentioned in the other solutions but none of them worked for me. In the end I tried opening the schema location file on a web browser but it wouldn't connect either (even though internet was working fine). Was the spring framework server down?
Turns out the Internet Security software that we use had to be turned on to access this site. So try opening the schema file in a web browser to verify that the URL is correct and that you can connect to it especially if the configuration was working fine previously.
I had a similar problem, it was giving the similar error for http://mybatis.org/schema/mybatis-spring.xsd file. Finally it was a missing jar in the application. I added the below dependency in my gradle file and that solved the problem
compile group: 'org.mybatis', name: 'mybatis-spring', version: '2.0.0'
So it could be a similar dependency or a spring jar missing in your application
Using Version-less dependencies is appreciated. Find my code below.
<?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/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<bean "class name goes here"> </bean>
</beans>

Why does DTD error "White spaces are required between publicId and systemI" occur with Spring XSD

In my application context file Eclipse shows the error:
Referenced file contains errors (http://www.springframework.org/schema/integration). applicationContext.xml line 1 XML Problem
looking at the error detail in Eclipse I see:
White spaces are required between publicId and systemId
According to other people with this problem it's related to the DOCTYPE which apparently must have a SYSTEM identifier.
Why in 2014 when DOCTYPE's are pretty much obsolete since we all use XSD instead of DTDs and there is no DOCTYPE in http://www.springframework.org/schema/integration (or should there be) does this error occur?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:mail="http://www.springframework.org/schema/integration/mail"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/integration/mail
http://www.springframework.org/schema/integration/mail/spring-integration-mail-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-3.0.xsd
http://www.springframework.org/schema/context/spring-context.xsd">
Thanks
You have to move spring-context.xsd to its id:
<beans
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-3.0.xsd">

failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans-3.0.xsd'

While starting my Spring App, I am getting the following error :
WARNING: Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document
'http://www.springframework.org/schema/beans/spring-beans-3.0.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>.
My springapp-servlet.xml is as follows :
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean name="/hello.htm" class="springapp.web.HelloController"/>
</beans>
Please suggest.
When I got this error message, it was merely because of a missing jar in my CLASSPATH. Some spring applications seem to be very hungry for spring jars. My app wound up needing all of these on the classpath:
${OTS_DIR}/org.springframework.aop-${VERSION}.jar:\
${OTS_DIR}/org.springframework.aspects-${VERSION}.jar:\
${OTS_DIR}/com.springsource.org.aopalliance-${AOPALLIANCE_VER}.jar:\
${OTS_DIR}/org.springframework.asm-${VERSION}.jar:\
${OTS_DIR}/org.springframework.beans-${VERSION}.jar:\
${OTS_DIR}/org.springframework.context-${VERSION}.jar:\
${OTS_DIR}/org.springframework.core-${VERSION}.jar:\
${OTS_DIR}/org.springframework.expression-${VERSION}.jar:\
${OTS_DIR}/org.springframework.jdbc-${VERSION}.jar:\
${OTS_DIR}/org.springframework.jms-${VERSION}.jar:\
${OTS_DIR}/org.springframework.orm-${VERSION}.jar:\
${OTS_DIR}/org.springframework.transaction-${VERSION}.jar:\
${OTS_DIR}/org.springframework.instrument-${VERSION}.jar
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Drools integrated with spring faced with a xsd not found warning

I'm using Spring+Drools in my Web Application.The following is the drools modules configuration
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:drools="http://drools.org/schema/drools-spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://drools.org/schema/drools-spring
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-container/drools-spring/src/main/resources/org/drools/container/spring/drools-spring-1.0.0.xsd"
default-autowire="byName">
<drools:kbase id="kbase1">
<drools:resources>
<drools:resource type="DRL" source="classpath:uniteStickyRules.drl"/>
</drools:resources>
</drools:kbase>
<drools:ksession id="ksession1" type="stateful" kbase="kbase1"/>
When I ran my application using this configuration in my junit project it worked, yet it came with the following problem when I startup my Web application. As a result, I couldnot find my kbase bean.
2012-03-29 12:55:48,402 WARN resolver.SpringPluggableSchemas - Could not find schema classpath:org/drools/container/spring/drools-service-spring.xsd for URI: http://drools.org/schema/drools-service-spring.xsd,
class path resource [org/drools/container/spring/drools-service-spring.xsd] cannot be resolved to URL because it does not exist
2012-03-29 12:55:48,413 WARN resolver.SpringPluggableSchemas - Could not find schema classpath:file:/C:/Users/Dan%20Diephouse/workspace/xfire/target/checkout/xfire-spring/target/test-generated/services.xsd for URI: http://xfire.codehaus.org/config/1.0,
class path resource [file:/C:/Users/Dan%20Diephouse/workspace/xfire/target/checkout/xfire-spring/target/test-generated/services.xsd] cannot be resolved to URL because it does not exist
You see, I didn't put the drools-service-spring.xsd in my .xml file. So I'm quite stuck with it. Any suggestions?

Resources