加载bean定义时Spring挂起

时间:2015-04-23 06:08:12

标签: java spring spring-mvc

我有以下Java代码:

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

以下应用程序上下文:

<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挂起。该申请没有回复。

找出我进行线程转储的原因。它似乎挂在TCP连接请求中:

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}

它尝试连接的地址是:

  

www.springframework.org/162.159.245.187

这里有什么问题?

1 个答案:

答案 0 :(得分:1)

检查POM文件。您在应用程序上下文中指定的schema命名空间是否与使用的Spring依赖项的正确版本相对应?

这里似乎发生的事情是Spring尝试从Spring XSD文件加载JAR文档,但由于版本不匹配而无法加载。所以它试图连接到Spring网站并从那里加载它。

将架构名称空间更改为正确版本解决了此问题:

<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">