3

I have following Java code:

ApplicationContext context = new ClassPathXmlApplicationContext
                ("classpath:applicationContext.xml");

And following application context:

<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: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-4.1.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">

<mvc:annotation-driven/>
    <context:component-scan base-package="in.ksharma"/>
</beans>

Spring hangs when loading this file. The application does not respond.

To find out why I took a thread dump. It seems to hang inside a TCP connect request:

connectToAddress():213, PlainSocketImpl {java.net}
connect():200, PlainSocketImpl {java.net}
connect():366, SocksSocketImpl {java.net}
connect():529, Socket {java.net}
connect():478, Socket {java.net}
doConnect():163, NetworkClient {sun.net}
openServer():411, HttpClient {sun.net.www.http}
openServer():525, HttpClient {sun.net.www.http}
<init>():208, HttpClient {sun.net.www.http}
New():291, HttpClient {sun.net.www.http}
New():310, HttpClient {sun.net.www.http}
getNewHttpClient():987, HttpURLConnection {sun.net.www.protocol.http}
plainConnect():923, HttpURLConnection {sun.net.www.protocol.http}
connect():841, HttpURLConnection {sun.net.www.protocol.http}
getInputStream():1195, HttpURLConnection {sun.net.www.protocol.http}
setupCurrentEntity():676, XMLEntityManager {com.sun.org.apache.xerces.internal.impl}
startEntity():1314, XMLEntityManager {com.sun.org.apache.xerces.internal.impl}
startDocumentEntity():1266, XMLEntityManager {com.sun.org.apache.xerces.internal.impl}
setInputSource():280, XMLDocumentScannerImpl {com.sun.org.apache.xerces.internal.impl}
parse():409, SchemaParsingConfig {com.sun.org.apache.xerces.internal.impl.xs.opti}
parse():491, SchemaParsingConfig {com.sun.org.apache.xerces.internal.impl.xs.opti}
parse():510, SchemaDOMParser {com.sun.org.apache.xerces.internal.impl.xs.opti}

The address it is trying to connect is:

www.springframework.org/162.159.245.187

What is the problem here?

Kshitiz Sharma
  • 17,947
  • 26
  • 98
  • 169

1 Answers1

3

Check the POM file. Does the schema namespace you have specified in application context correspond to the correct version of Spring dependencies used?

What seems to be happening here is that Spring tries to load the XSD document from the Spring JAR file but is unable to do so due to version mismatch. So it tries to connect to Spring website and load it from there.

Changing the schema namespace to correct version resolved this problem:

<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:mvc="http://www.springframework.org/schema/mvc"
       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
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
Kshitiz Sharma
  • 17,947
  • 26
  • 98
  • 169
  • Why did you answer your own question almost immediately? – Jeevan Patil Apr 23 '15 at 06:15
  • 2
    He's also talking to himself as if he was 2 people, so I'd rather not know. – kaqqao Apr 23 '15 at 06:18
  • 1
    @Jeevan I had already figured out the answer by myself. Shared it here in QA format for the benefit of others. – Kshitiz Sharma Apr 23 '15 at 06:34
  • 3
    No I shouldn't. If you think this is wrong flag it for moderator attention or take it to meta. As per the [SO policy](http://stackoverflow.com/help/self-answer): `If you have a question that you already know the answer to, and you would like to document that knowledge in public so that others (including yourself) can find it later, it's perfectly okay to ask and answer your own question on a Stack Exchange site.` – Kshitiz Sharma Apr 23 '15 at 06:46
  • I think you should check your internet connection becuase the 4.1 version also exists. and it is trying to download it from the site – igreenfield Apr 23 '15 at 07:25
  • @igreen Yes I know. The company proxy could be blocking the connection. In any case its better to load same version of XSD as the Spring JAR version. – Kshitiz Sharma Apr 23 '15 at 07:51
  • Which spring version you have in the class path? – igreenfield Apr 23 '15 at 11:43
  • 1
    @JeevanPatil웃 Answering your own questions is allowed and encouraged, as explained in [the document the author linked above](http://stackoverflow.com/help/self-answer). – Jeremy Apr 25 '15 at 23:36