junit的ant目标无法加载spring context xml文件

时间:2011-06-09 10:32:14

标签: spring ant junit

当我为junit运行ant目标时,会发生以下错误:

    Configuration problem: Failed to import bean definitions from URL location [classpath:/esw-web-ctx.xml] Offending resource: class path resource [applicationContext.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:/com/bgc/ecm/core/tools/exceptions/errorpagehandler-ctx.xml] Offending resource: class path resource [esw-web-ctx.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [com/bgc/ecm/core/tools/exceptions/errorpagehandler-ctx.xml]; nested exception is java.net.UnknownHostException: www.springframework.org

    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:/esw-web-ctx.xml]
    Offending resource: class path resource [applicationContext.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:/com/bgc/ecm/core/tools/exceptions/errorpagehandler-ctx.xml]
    Offending resource: class path resource [esw-web-ctx.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [com/bgc/ecm/core/tools/exceptions/errorpagehandler-ctx.xml]; nested exception is java.net.UnknownHostException: www.springframework.org
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76).......
......

Ant目标:

<target name="junit" depends="buildlocal">  
    <delete dir="${JUNIT_REPORT}" failonerror="false"/>
    <mkdir dir="${BUILD_TEST_DIR}" />
    <mkdir dir="${JUNIT_REPORT}" />
    <echo message="Launching JUnit tests" />    
    <copy todir="${BUILD_TEST_DIR}/" overwrite="true">
        <fileset dir="${COMP_TESTCONFIG_DIR}">
            <exclude name="*.properties.template" />
            <exclude name="*.xml.template" />
            <exclude name="*.ccf.template" />
            <exclude name="**/*.bak" />
            <exclude name="**/*.keep" />
            <exclude name="**/*.keep.*" />
            <exclude name="**/*.contrib" />
            <exclude name="**/*.java" />
            <exclude name="**/*.class" />
            <exclude name="**/*.contrib.*" />
        </fileset>
    </copy>  
    <junit printsummary="on" fork="off" haltonfailure="false" failureproperty="junit.failure" showoutput="false">
        <classpath>
            <path refid="CLASSPATH_JUNIT"/>             
        </classpath>            
        <batchtest fork="off"  todir="${BUILD_TEST_DIR}">
           <fileset dir="${TEST_CLASSES_DIR}">
              <include name="**/*Test.class" />
              <include name="**/Test*.class" />     
              <!-- <exclude name="**/EswCacheInitializerTest.class" /> -->      
           </fileset> 
        </batchtest>
        <formatter type="xml" />
    </junit>        
    <echo message="Launching junitreport" />    
    <junitreport todir="${JUNIT_REPORT}">
        <fileset dir="${BUILD_TEST_DIR}">
            <include name="TEST-*.xml" />           
        </fileset>       
        <report format="frames" todir="${JUNIT_REPORT}"/>       
    </junitreport>
    <delete dir="${BUILD_TEST_DIR}" failonerror="false"/>       
    <echo message="**** Junit report generated at the location: ${JUNIT_REPORT} ***"/>
    <echo message="==============================================="/>
    <echo message="******  JUNIT BUILD ENDS - CORE    ******      "/>
    <echo message="==============================================="/>
    <fail if="junit.failure" message="Unit test(s) failed.  See reports at: ${JUNIT_REPORT}"/>
</target>
<path id="CLASSPATH_JUNIT">
    <path refid="LIB_JAVAC"/>
    <pathelement location="${TEST_CLASSES_DIR}" />
    <pathelement location="${BUILD_TEST_DIR}" />
    <pathelement location="${APP_DIR}\bgc-esw-core\target\classes" />
    <pathelement location="${APP_DIR}\bgc-esw-web\target\classes" />
    <pathelement location="${APP_DIR}\bgc-esw-wicket-components\target\classes" />  
    <fileset dir="${BUILD_LIBS_HOME}">
        <include name="*.jar" />
    </fileset>  
    <fileset dir="${APP_DIR}\bgc-esw-web\build" erroronmissingdir="false">
        <include name="bgc-esw-*.jar" />            
    </fileset>  
    <fileset dir="${APP_DIR}\bgc-esw-services\build" erroronmissingdir="false">
        <include name="bgc-esw-service*.jar" />
    </fileset>  
    <fileset dir="${APP_DIR}\bgc-esw-core\build" erroronmissingdir="false">
        <include name="bgc-esw-core*.jar" />
    </fileset>  
    <fileset dir="${APP_DIR}\bgc-esw-wicket-components\build" erroronmissingdir="false">
        <include name="bgc-esw-wicket-components*.jar" />
    </fileset>  
</path>

1 个答案:

答案 0 :(得分:0)

检查该应用程序上下文定义中的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:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:security="http://www.springframework.org/schema/security"
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/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">

我敢打赌,一些Spring XSD文件不在你的类路径的jar中;所有这些都应该在您的系统上本地,而不是从网上下载。