Spring-Ibatis部署例外

时间:2012-08-08 08:52:38

标签: spring ant ibatis

例外:

 Caused by: org.springframework.core.NestedIOException: Failed to parse config resource: ServletContext resource [/WEB-INF/SqlMapConfig.xml]; nested exception is com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.  Cause: java.io.IOException: Could not find resource WEB-INF/ADCampaignDetailsSQLMap.xml

SqlMapConfig.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL MAP Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
    <settings useStatementNamespaces="true"/>

    <sqlMap resource="WEB-INF/ADCampaignDetailsSQLMap.xml"/>
</sqlMapConfig>

ADCampaignDetailsS​​QLMap.xml放在我的项目文件夹

的WEB-INF中

当我将war文件复制到webapps文件夹时,会引发Above异常。

任何人都能为我解决这个问题吗?

提前致谢

修改

的build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project
    name="adblendservice"
    default="war" >

    <property environment="env" />

    <property
        name="builddir"
        value="build/" />

    <property
        name="srcdir"
        value="src/main/java/" />

    <property
        name="deploydir"
        value="deploy/" />

    <property
        name="wardir"
        value="src/main/webapp/" />

    <property
        name="libdir"
        value="${wardir}/WEB-INF/lib/" />

    <property file="build.properties" />

    <path id="project-classpath" >

        <fileset
            dir="web/WEB-INF/lib"
            includes="*.jar" />

        <fileset
            dir="${tomcat-home}/lib"
            includes="*.jar" />
        <!--
            <fileset dir="${tomcat-home}/common/lib" includes="*.jar" />
            <fileset dir="${tomcat-home}/server/lib" includes="*.jar" />
        -->
    </path>

    <target name="clean" >

        <delete
            dir="${builddir}"
            failonerror="true" />

        <echo message="Creating build directories" />
    </target>

    <target name="war" >

        <mkdir dir="${builddir}" />

        <mkdir dir="${builddir}/adblendservice/WEB-INF/classes" />

        <mkdir dir="${deploydir}" />

        <path id="basepath" >

            <fileset dir="${wardir}/WEB-INF/lib" >

                <include name="**/*.jar" />
            </fileset>
        </path>

        <javac
            destdir="${builddir}/adblendservice/WEB-INF/classes"
            includeantruntime="false"
            srcdir="${srcdir}" >

            <classpath refid="basepath" />
        </javac>

        <war
            update="update"
            warfile="${builddir}/adblendservice.war"
            webxml="${wardir}/WEB-INF/web.xml" >

            <classes dir="${builddir}/adblendservice/WEB-INF/classes" />

            <fileset dir="${srcdir}" >
                <include name="**/*.xml" />
            </fileset>

            <lib dir="${wardir}/WEB-INF/lib" />

            <fileset dir="${wardir}" >

                <include name="**/*.xml" />
            </fileset>
        </war>
    </target>

    <target
        name="deploy"
        depends="clean, war" >

        <copy
            file="${builddir}/adblendservice.war"
            todir="${deploydir}" >
        </copy>
    </target>

</project>

2 个答案:

答案 0 :(得分:1)

iBatis搜索xml文件的类路径的根目录是WEB-INF/classes,而不是公共网站的根目录。
尝试将xml移动到classes目录并指向它而不使用路径。

答案 1 :(得分:0)

将XML文件移动到类路径,或者如果它在类路径之外,则指定路径,如<sqlMap resource="../WEB-INF/ADCampaignDetailsSQLMap.xml"/>