报了一个配置文件出错

来源:3-2 SQL 基本配置与执行

模棱0

2016-12-06 15:45

public SqlSession getSqlSession() throws IOException{

//通过配置文件获取数据库连接相关信息

Reader reader = Resources.getResourceAsReader("com/abe/config/mybatis.xml");

//通过配置信息构建SQLSessionFactory

SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);

//通过SQLSessionFactory打开数据库回话

SqlSession sqlSession = sqlSessionFactory.openSession();

return sqlSession;

}


public List<Message> queryMessageList(String command, String description) {

DBAccess dbAccess = new DBAccess();

SqlSession sqlSession = null;

List<Message> messageList = new ArrayList<Message>();

try {

sqlSession = dbAccess.getSqlSession();

//通过SqlSession执行sql语句

messageList = sqlSession.selectList("Message.queryMessageList");

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally{

if (sqlSession != null) {

sqlSession.close();

}

}

return messageList;

}

<mapper namespace="Message"> 

<!-- 必须加载 namespace,在同一个namespace中select标签的id只能是唯一的。在不同的namespace中可以存在不相同的select标签id -->


  <resultMap type="com.abe.bean.Message" id="MessageResult">

  <!-- resultMap中的id属性与select中的id属性没有任何连接 -->

    <id column="id" jdbcType="INTEGER" property="id"/> <!-- 数据库中的主键名用id标签 -->

    <result column="COMMAND" jdbcType="VARCHAR" property="command"/><!-- 数据库中的其他字段用result标签 -->

    <result column="DESCRIPTION" jdbcType="VARCHAR" property="description"/>

    <result column="CONTENT" jdbcType="VARCHAR" property="content"/>

  </resultMap>


<!-- 查询得到的字段放置到resultMap对应的属性中 -->

  <select id="queryMessageList" resultMap="MessageResult">

    select ID,COMMAND,DESCRIPTION,CONTENT from MESSAGE where 1=1

  </select>

麻烦大家帮我看看   谢谢

写回答 关注

4回答

  • 慕哥645704
    2017-08-27 11:20:16

    我也出过这错误,我的错误是resultMap中的type包名复制的时候少了个字母。你这是不是主键数据库id小写了的原因啊,我初学者,不知道这个严不严格区分大小写

  • 奋斗的大象
    2016-12-08 15:12:06

    可能是你的“com/abe/config/mybatis.xml”文件里面有问题,能把你的这个文件内容粘贴出来吗

  • 模棱0
    2016-12-07 11:20:15

    HTTP Status 500 -

    type Exception report

    message

    description The server encountered an internal error that prevented it from fulfilling this request.

    exception

    org.apache.ibatis.exceptions.PersistenceException:
    ### Error building SqlSession.
    ### The error may exist in com/abe/config/sql/Message.xml
    ### The error occurred while processing mapper_resultMap[MessageResult]
    ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'UserAlias'.  Cause: java.lang.ClassNotFoundException: Cannot find class: UserAlias
    org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:54)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38)
    com.abe.db.DBAccess.getSqlSession(DBAccess.java:20)
    com.abe.dao.MessageDao.queryMessageList(MessageDao.java:27)
    com.abe.service.ListService.queryMessageList(ListService.java:14)
    com.abe.servlet.ListServlet.doGet(ListServlet.java:39)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

    root cause

    org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'UserAlias'.  Cause: java.lang.ClassNotFoundException: Cannot find class: UserAlias
    org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:109)
    org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:92)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38)
    com.abe.db.DBAccess.getSqlSession(DBAccess.java:20)
    com.abe.dao.MessageDao.queryMessageList(MessageDao.java:27)
    com.abe.service.ListService.queryMessageList(ListService.java:14)
    com.abe.servlet.ListServlet.doGet(ListServlet.java:39)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

    root cause

    org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'UserAlias'.  Cause: java.lang.ClassNotFoundException: Cannot find class: UserAlias
    org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120)
    org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)
    org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:322)
    org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:107)
    org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:92)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38)
    com.abe.db.DBAccess.getSqlSession(DBAccess.java:20)
    com.abe.dao.MessageDao.queryMessageList(MessageDao.java:27)
    com.abe.service.ListService.queryMessageList(ListService.java:14)
    com.abe.servlet.ListServlet.doGet(ListServlet.java:39)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

    root cause

    org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'UserAlias'.  Cause: java.lang.ClassNotFoundException: Cannot find class: UserAlias
    org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:103)
    org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:66)
    org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:135)
    org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:128)
    org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:118)
    org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)
    org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:322)
    org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:107)
    org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:92)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38)
    com.abe.db.DBAccess.getSqlSession(DBAccess.java:20)
    com.abe.dao.MessageDao.queryMessageList(MessageDao.java:27)
    com.abe.service.ListService.queryMessageList(ListService.java:14)
    com.abe.servlet.ListServlet.doGet(ListServlet.java:39)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

    root cause

    org.apache.ibatis.type.TypeException: Could not resolve type alias 'UserAlias'.  Cause: java.lang.ClassNotFoundException: Cannot find class: UserAlias
    org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:117)
    org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:130)
    org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:101)
    org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:66)
    org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:135)
    org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:128)
    org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:118)
    org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)
    org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:322)
    org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:107)
    org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:92)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38)
    com.abe.db.DBAccess.getSqlSession(DBAccess.java:20)
    com.abe.dao.MessageDao.queryMessageList(MessageDao.java:27)
    com.abe.service.ListService.queryMessageList(ListService.java:14)
    com.abe.servlet.ListServlet.doGet(ListServlet.java:39)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

    root cause

    java.lang.ClassNotFoundException: Cannot find class: UserAlias
    org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:190)
    org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:89)
    org.apache.ibatis.io.Resources.classForName(Resources.java:256)
    org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:113)
    org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:130)
    org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:101)
    org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:66)
    org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:135)
    org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:128)
    org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:118)
    org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)
    org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:322)
    org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:107)
    org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:92)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38)
    com.abe.db.DBAccess.getSqlSession(DBAccess.java:20)
    com.abe.dao.MessageDao.queryMessageList(MessageDao.java:27)
    com.abe.service.ListService.queryMessageList(ListService.java:14)
    com.abe.servlet.ListServlet.doGet(ListServlet.java:39)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

    note The full stack trace of the root cause is available in the Apache Tomcat/8.0.36 logs.


  • 奋斗的大象
    2016-12-06 16:57:27

    看程序,没发现问题,有错误的具体信息吗

通过自动回复机器人学Mybatis---基础版

微信公众号自动回复功能学习Mybatis,基础教程加案例实战方式学习

107412 学习 · 786 问题

查看课程

相似问题