代码和官方的example是一样的可就是出现
下面问题:Attribute "recource" must be declared for element type "properties".
SqlMapConfig.xml<?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>  <!-- Configure a built-in transaction manager.  If you're using an 
       app server, you probably want to use its transaction manager 
       and a managed datasource -->
  <transactionManager type="JDBC">
    <dataSource type="SIMPLE">
      <property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
      <property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost/test"/>
      <property name="JDBC.Username" value="root"/>
      <property name="JDBC.Password" value="123456"/>
    </dataSource>
  </transactionManager>  <!-- List the SQL Map XML files. They can be loaded from the 
       classpath, as they are here (com.domain.data...) -->
  <sqlMap resource="com/mydomain/data/Account.xml"/>
  <!-- List more here...
  <sqlMap resource="com/mydomain/data/Order.xml"/>
  <sqlMap resource="com/mydomain/data/Documents.xml"/>
  --></sqlMapConfig>
Account.xml文件<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE sqlMap      
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"      
    "http://ibatis.apache.org/dtd/sql-map-2.dtd"><sqlMap namespace="Account">  <!-- Use type aliases to avoid typing the full classname every time. -->
  <typeAlias alias="Account" type="com.mydomain.domain.Account"/>  <!-- Result maps describe the mapping between the columns returned
       from a query, and the class properties.  A result map isn't
       necessary if the columns (or aliases) match to the properties 
       exactly. -->  <resultMap id="AccountResult" class="Account">
    <result property="id" column="id"/>
    <result property="name" column="name"/>
    <result property="age" column="age"/>
  </resultMap>  <!-- Select with no parameters using the result map for Account class. -->
  <select id="selectAllAccounts" resultMap="AccountResult">
    select * from student
  </select></sqlMap>高手帮忙看看!到底是什么原因啊?

解决方案 »

  1.   

    控制台的错误信息:java.lang.RuntimeException: Error occurred.  Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: org.xml.sax.SAXParseException: Attribute "recource" must be declared for element type "properties".
    at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:49)
    at com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(SqlMapClientBuilder.java:63)
    at test.IStudentDAOImpl.<init>(IStudentDAOImpl.java:17)
    at test.IStudentDAOImpl.main(IStudentDAOImpl.java:69)
    Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: org.xml.sax.SAXParseException: Attribute "recource" must be declared for element type "properties".
    at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)
    at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser.parse(SqlMapConfigParser.java:46)
    ... 3 more
    Caused by: org.xml.sax.SAXParseException: Attribute "recource" must be declared for element type "properties".
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at com.ibatis.common.xml.NodeletParser.createDocument(NodeletParser.java:157)
    at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:50)
    ... 4 more
      

  2.   

    看这两个文件的内容还真看不出来!
    思路:
    1、定位问题在哪里?将 <sqlMap resource="com/mydomain/data/Account.xml"/> 注释掉看看
    2、如果没有问题,那么将注释去掉,在将 Account.xml 的内容不部分去掉,排除
    3、这样进一步定位问题
      

  3.   

    高手再帮忙看看测试代码有没有什么问题:package com.mydomain.data;import com.ibatis.sqlmap.client.SqlMapClient;
    import com.ibatis.sqlmap.client.SqlMapClientBuilder;
    import com.ibatis.common.resources.Resources;
    import com.mydomain.domain.Account;import java.io.Reader;
    import java.io.IOException;
    import java.util.List;
    import java.sql.SQLException;import test.IStudentDAO;
    import test.IStudentDAOImpl;
    import test.Student;/**
     * This is not a best practices class. It's just an example to give you an idea
     * of how iBATIS works. For a more complete example, see JPetStore 5.0 at
     * http://www.ibatis.com.
     */
    public class SimpleExample { /**
     * SqlMapClient instances are thread safe, so you only need one. In this
     * case, we'll use a static singleton. So sue me. ;-)
     */
    private static SqlMapClient sqlMapper; /**
     * It's not a good idea to put code that can fail in a class initializer,
     * but for sake of argument, here's how you configure an SQL Map.
     */
    static {
    try {
    Reader reader = Resources
    .getResourceAsReader("com/mydomain/data/SqlMapConfig.xml");
    sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
    reader.close();
    } catch (IOException e) {
    // Fail fast.
    throw new RuntimeException(
    "Something bad happened while building the SqlMapClient instance."
    + e, e);
    }
    } @SuppressWarnings("unchecked")
    public static List selectAllAccounts() throws SQLException {
    return sqlMapper.queryForList("selectAllAccounts");
    } public static Account selectAccountById(int id) throws SQLException {
    return (Account) sqlMapper.queryForObject("selectAccountById", id);
    } public static void insertAccount(Account account) throws SQLException {
    sqlMapper.insert("insertAccount", account);
    } public static void updateAccount(Account account) throws SQLException {
    sqlMapper.update("updateAccount", account);
    } public static void deleteAccount(int id) throws SQLException {
    sqlMapper.delete("deleteAccount", id);
    }

    public static void main(String[] args)
    {
    try {
    IStudentDAO dao=new IStudentDAOImpl();

    for(Student student:dao.queryallstudent())
    {
    System.err.println(student);
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }}
      

  4.   

    java.lang.RuntimeException: Error occurred.  Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: org.xml.sax.SAXParseException: Attribute "recource" must be declared for element type "properties".你的某一个xml 文件中是不是有个 recource? 我觉得你应该把这个改成 resource, 
       
      

  5.   

    <sqlMapConfig>
    后面加一行
    <properties resource="sqlMapconfig.properties" />同目录 建立一个 sqlMapconfig.properties,空白的也行,这个是可以用来配置 数据库信息的
      

  6.   

    resource改成别的就有错误了!
      

  7.   

    在linux下,我也出了同样的错误,找不出原因。郁闷中,望高手解决!