• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Failed to read schema document in Spring MVC project in root-context.xml

 
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello;

I am running Spring MVC project and when I reached for deployment (I generated WAR file for deployment team and they use it to do the deployment), I faced an error that we were not see it when we were running the project from eclipse (Run as Maven Build). I am sure this is because the deployment is happening on machine that does not have Internet. The error is related to downloading the XSD file that is needed in the root-context.xml file.

The error is saying:



I know that I have to place the spring-beans.xsd file locally and change the xml configuration to direct for it, but I do not know in which path I have to place this file and what the configuration that I have to place in the root-context.xml file to be able to find this file.

From the other side, I am posting here the root-context.xml file:




Appreciate the kindly help please.

Regards
Bilal
 
Saloon Keeper
Posts: 11441
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're deploying a Spring application to a host that doesn't have internet? Is this an intranet application?

Anyway, if it's only a warning, can't you just ignore it? Or does it fail to run the application?
 
Saloon Keeper
Posts: 21710
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Spring forum, since there's nothing JSF in this thread.
 
Bilal Ghayad
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your kindly reply and support.

It is error and below is the error line:



And yes, this problem is appearing because there is no Internet but of course there is network.
The project is failing to run.

Regards
Bilal
 
Marshal
Posts: 25143
64
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The tool which converts a network entity to a local entity is called an XML catalog (as the Wikipedia article says). I googled a bit to see how to inject an XML catalog into Spring MVC with no success, but I didn't try very hard. You'd think there would be a way to do that.
 
Ranch Hand
Posts: 1815
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Bilal,
Can you try to add <context:annotation-config/> to your <beans> ?
It should be something like this:


Reference:
https://stackoverflow.com/questions/13814321/cannot-find-the-declaration-of-element-beans
 
Tim Holloway
Saloon Keeper
Posts: 21710
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
https://en.wikipedia.org/wiki/XML_catalog

Their example is for a DTD, but XML schema works the same way. In either case, if you do not have an Internet connection that can be used to resolve a schema or DTD, then you must provide an alternative mechanism. This is often done by modifying the xsi:schemaLocation to point to a local file instead of to a URL, but can also be done by attaching a catalog resolver to the XML parser being used (for example, SAX).

In the case of the Spring beans, I think that actually you might find the schemas you need as files within their respective JAR libraries (look in the META-INF directory). And in that case, normally Spring would be able to deal with the schema without any additional effort. Unless, of course, Spring was improperly configured or initialized.

Here's an old, but perfectly valid snippet from a web application of mine. This is the head of the /WEB-INF/applicationContext.xml file.

 
Bilal Ghayad
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Tim and All;

Thanks a lot for all of you.

This is often done by modifying the xsi:schemaLocation to point to a local file instead of to a URL



My problem is where to place this XSD file and how to direct for it locally.

Let me tell you what did and what I obtained and where is my problem:

I placed the file required XSD files in my local computer and this was under this path: C:/Users/Bilal/.m2/repository/org/springframework/spring-beans/factory/xml/spring-beans.xsd

And I was able to direct for it using this syntax:

xsi:schemaLocation="http://www.springframework.org/schema/beans file:///C:/Users/Bilal/.m2/repository/org/springframework/spring-beans/factory/xml/spring-beans.xsd"

But where is the problem of using file:///C:/Users/Bilal/.m2/repository/org/springframework/spring-beans/factory/xml/spring-beans.xsd?

The problem is that this directory at my laptop, and when we do deployment using the war file, this path will not be existed and the files will not be available.

I need to place this XSD file in a path that is exported with war file and I need to know how to direct for it properly, using file: or using classpath:? How the syntax will be?

Appreciate the kindly help please.
Regards
Bilal

 
Tim Holloway
Saloon Keeper
Posts: 21710
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It wouldn't be a good idea to look inside a hidden directory - and especially your local Maven repo directory - for a schema file.

I did a quick check and not only the current version of the spring beans schema is located within the spring-beans jar, so are several previous versions.

So you are evidently not initializing Spring properly. I mix Spring with JSF and haven't touched any of that stuff recently, so I don't have any good advice there, but the sample I gave you is exactly what I build into my WAR, and I'm fairly certain that it's not actually going to the Internet to resolve those URLs, but rather using an internal resolver to get them from their location in the jar automatically.
 
Bilal Ghayad
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK I understood you, I have to keep it directing for http and I have to add internal resolver.

Can you direct me how you did the internal resolver and instead of going to the internet, it is finding them locally, how?

Regards
Bilal
 
Tim Holloway
Saloon Keeper
Posts: 21710
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't do anything. It's automatically done by Spring when Spring is properly configured.
 
Bilal Ghayad
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for all of you. I found the problem.
The reason of the problem was because the url was https and not http and when I checked the spring.schemas which contains the mapping, it was configured for http and not https. So all what I did, I changed the https to http instead of https and the error went out.


root-context.xml after changing the link from https to http:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">




spring.schemas:

http\://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-4.3.xsd




Regards
Bilal
 
Tim Holloway
Saloon Keeper
Posts: 21710
148
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooooh, that's a sneaky one! Congratulations on figuring it out - and posting the information for the rest of us.

HTTP is so far down the road to obsolescence that it would have never even occurred to me that even a public read-only resource might still be referenced that way.
 
They worship nothing. They say it's because nothing is worth fighting for. Like this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!