ibatis中xml解析问题Attribute "recource" must be declared for element type "properties

lgq_0714 2009-06-12 10:49:43
代码和官方的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>

高手帮忙看看!到底是什么原因啊?
...全文
2714 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
javamyself 2011-07-28
  • 打赏
  • 举报
回复
问题解决了也要贴出来分享下好不?曰!..
thb_763675117 2009-12-29
  • 打赏
  • 举报
回复
在linux下,我也出了同样的错误,找不出原因。郁闷中,望高手解决!
lgq_0714 2009-06-13
  • 打赏
  • 举报
回复
高手清指点!
jastby 2009-06-12
  • 打赏
  • 举报
回复
是哦 同5楼 好像单词错了 搜索一下这个单词 看看出现在哪里
jastby 2009-06-12
  • 打赏
  • 举报
回复
<sqlMapConfig>
后面加一行
<properties resource="sqlMapconfig.properties" />

同目录 建立一个 sqlMapconfig.properties,空白的也行,这个是可以用来配置 数据库信息的
laorer 2009-06-12
  • 打赏
  • 举报
回复
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,
lgq_0714 2009-06-12
  • 打赏
  • 举报
回复
高手过来帮忙看看!!
lgq_0714 2009-06-12
  • 打赏
  • 举报
回复
高手再帮忙看看测试代码有没有什么问题:

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();
}
}

}
victorxiang 2009-06-12
  • 打赏
  • 举报
回复
看这两个文件的内容还真看不出来!
思路:
1、定位问题在哪里?将 <sqlMap resource="com/mydomain/data/Account.xml"/> 注释掉看看
2、如果没有问题,那么将注释去掉,在将 Account.xml 的内容不部分去掉,排除
3、这样进一步定位问题
lgq_0714 2009-06-12
  • 打赏
  • 举报
回复
控制台的错误信息:

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
lgq_0714 2009-06-12
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 jastby 的回复:]
是哦 同5楼 好像单词错了 搜索一下这个单词 看看出现在哪里
[/Quote]
resource改成别的就有错误了!

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧