简体   繁体   中英

iBatis - Why is sqlMapConfig.xml unable to find the sql maps defined in it?

I have a sqlMapConfig.xml that has three SQLMaps defined in it.

    <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE sqlMapConfig
    PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

  <sqlMapConfig>
    <!-- Statement namespaces are required for Ibator -->
   <settings enhancementEnabled="true" useStatementNamespaces="true"/>

    <!-- Setup the transaction manager and data source that are
         appropriate for your environment
    -->
    <transactionManager type="JDBC">
        <dataSource type="SIMPLE" >
            <property name="JDBC.Driver"
                value="com.mysql.jdbc.Driver"/>
            <property name="JDBC.ConnectionURL"
                value="jdbc:mysql://localhost:3306/sug"/>
            <property name="JDBC.Username"
                value="root"/>
            <property name="JDBC.Password"
                value="admin"/>
        </dataSource>
    </transactionManager>

    <!-- SQL Map XML files should be listed here -->
    <sqlMap resource="com/tatakelabs/dbmaps/categories_SqlMap.xml" />
    <sqlMap resource="com/tatakelabs/dbmaps/pro_SqlMap.xml" />
    <sqlMap resource="com/tatakelabs/dbmaps/pro_category_SqlMap.xml" />

  </sqlMapConfig>

I get a runtime error - Cause: java.io.IOException: Could not find resource com/tatakelabs/dbmaps/categories_SqlMap.xml

categories_SqlMap.xml is present in that location. I tried changing the location of the map xml, but that did not help. sqlMapConfig.xml validates against the DTD. categories_SqlMap.xml also validates against the right DTD. I am at my wits end trying to figure out why it can't find the resource. The sqlMap files are generated by iBator.

This was happening because the sqlmap file location was not getting copied to target. Added a copy goal and that fixed it.

I had the same problem. It appears the problem lies with the location of the config file. Thus, its in relation of the project resource structure.

I moved the config file in the same package as the mapper classes and it worked. In this case try moving all the resources to this package and update the resource attributes to:

<sqlMap resource="categories_SqlMap.xml" />
<sqlMap resource="pro_SqlMap.xml" />
<sqlMap resource="pro_category_SqlMap.xml" />

将它放在Source Packages目录下的... src \\ java \\ abc.xml中。

Solved it.

I moved the xml file to where the Pojo was located and provided the path as follows:

<sqlMap resource="com/heena/ibatis/model/jsr/jsr.xml" />

And it worked.

If you are using Spring, you can use a SqlMapClientFactoryBean specifying property "mappingLocations". In this property you can specify a generic path, such as "com/tatakelabs/dbmaps/*_SqlMap.xml" or with a variable such as ${mapfiles}, that will be resolved by Spring as an array of file names. This lets you omit sqlMap element in sqlMapConfig. This technique will run with iBatis 2.3.4 on. However sql-map-config-2.dtd is also contained inside iBatis.jar, so you can experience some parsing errors, as /com/ibatis/sqlmap/engine/builder/xml/sql-map-config-2.dtd may have a bug. In this case you may want to replace it inside the jar with the one from the URL: http://ibatis.apache.org/dtd/sql-map-config-2.dtd .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM