问答详情
源自:4-2 动态 SQL 拼接(下)

500错误

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/imooc/config/sqlxml/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 ' com.imooc.bean.Message'.  Cause: java.lang.ClassNotFoundException: Cannot find class:  com.imooc.bean.Message
org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:54)
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38)
com.imooc.db.DBAccess.getSqlSession(DBAccess.java:17)
com.imooc.dao.MessageDao.queryMessageList(MessageDao.java:23)
com.imooc.service.ListService.queryMessageList(ListService.java:14)
com.imooc.servlet.ListServlet.doGet(ListServlet.java:35)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
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 ' com.imooc.bean.Message'.  Cause: java.lang.ClassNotFoundException: Cannot find class:  com.imooc.bean.Message
org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:118)
org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:96)
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38)
com.imooc.db.DBAccess.getSqlSession(DBAccess.java:17)
com.imooc.dao.MessageDao.queryMessageList(MessageDao.java:23)
com.imooc.service.ListService.queryMessageList(ListService.java:14)
com.imooc.servlet.ListServlet.doGet(ListServlet.java:35)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
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 ' com.imooc.bean.Message'.  Cause: java.lang.ClassNotFoundException: Cannot find class:  com.imooc.bean.Message
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:360)
org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:116)
org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:96)
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38)
com.imooc.db.DBAccess.getSqlSession(DBAccess.java:17)
com.imooc.dao.MessageDao.queryMessageList(MessageDao.java:23)
com.imooc.service.ListService.queryMessageList(ListService.java:14)
com.imooc.servlet.ListServlet.doGet(ListServlet.java:35)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
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 ' com.imooc.bean.Message'.  Cause: java.lang.ClassNotFoundException: Cannot find class:  com.imooc.bean.Message
org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:118)
org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:265)
org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:252)
org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:244)
org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:116)
org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)
org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:360)
org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:116)
org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:96)
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38)
com.imooc.db.DBAccess.getSqlSession(DBAccess.java:17)
com.imooc.dao.MessageDao.queryMessageList(MessageDao.java:23)
com.imooc.service.ListService.queryMessageList(ListService.java:14)
com.imooc.servlet.ListServlet.doGet(ListServlet.java:35)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


root cause

org.apache.ibatis.type.TypeException: Could not resolve type alias ' com.imooc.bean.Message'.  Cause: java.lang.ClassNotFoundException: Cannot find class:  com.imooc.bean.Message
org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:120)
org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:149)
org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:116)
org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:265)
org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:252)
org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:244)
org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:116)
org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)
org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:360)
org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:116)
org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:96)
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38)
com.imooc.db.DBAccess.getSqlSession(DBAccess.java:17)
com.imooc.dao.MessageDao.queryMessageList(MessageDao.java:23)
com.imooc.service.ListService.queryMessageList(ListService.java:14)
com.imooc.servlet.ListServlet.doGet(ListServlet.java:35)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


root cause

java.lang.ClassNotFoundException: Cannot find class:  com.imooc.bean.Message
org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:200)
org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:89)
org.apache.ibatis.io.Resources.classForName(Resources.java:261)
org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:116)
org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:149)
org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:116)
org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:265)
org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:252)
org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:244)
org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:116)
org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)
org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:360)
org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:116)
org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:96)
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38)
com.imooc.db.DBAccess.getSqlSession(DBAccess.java:17)
com.imooc.dao.MessageDao.queryMessageList(MessageDao.java:23)
com.imooc.service.ListService.queryMessageList(ListService.java:14)
com.imooc.servlet.ListServlet.doGet(ListServlet.java:35)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
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/7.0.53 logs.

Apache Tomcat/7.0.53

Message.xml代码:

<?xml version="1.0" encoding="UTF-8"?>

<!--

       Copyright 2009-2012 the original author or authors.

       Licensed under the Apache License, Version 2.0 (the "License");

       you may not use this file except in compliance with the License.

       You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing, software

       distributed under the License is distributed on an "AS IS" BASIS,

       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

       See the License for the specific language governing permissions and

       limitations under the License.


-->


<!DOCTYPE mapper

    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"

    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">


<mapper namespace="Message">


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

    <id column="ID" jdbcType="INTEGER" property="id"/>

    <result column="COMMAND" jdbcType="VARCHAR" property="command"/>

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

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

  </resultMap>


  <select id="queryMessageList" parameterType="com.imooc.bean.Message" resultMap="MessageResult">

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

  <if test="command!=null &amp;&amp;!&quot;&quot;equals(command.trim())">

  and COMMAND = #{command} 

  </if>

  <if test="description!=null &amp;&amp;!&quot;&quot;equals(description.trim())">

  and DESCRIPTION like '%'  #{description}  '%'

  </if>

  </select>


</mapper>



提问者:qq_柒分醉_03927370 2017-05-24 22:55

个回答

  • qq_柒分醉_03927370
    2017-05-25 09:36:03

    <?xml version="1.0" encoding="UTF-8" ?>

    <!--


           Copyright 2009-2012 the original author or authors.


           Licensed under the Apache License, Version 2.0 (the "License");

           you may not use this file except in compliance with the License.

           You may obtain a copy of the License at


              http://www.apache.org/licenses/LICENSE-2.0


           Unless required by applicable law or agreed to in writing, software

           distributed under the License is distributed on an "AS IS" BASIS,

           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

           See the License for the specific language governing permissions and

           limitations under the License.


    -->

    <!DOCTYPE configuration

        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"

        "http://mybatis.org/dtd/mybatis-3-config.dtd">


    <configuration>

    <!--  

      <settings>

        <setting name="useGeneratedKeys" value="false"/>

        <setting name="useColumnLabel" value="true"/>

      </settings>


      <typeAliases>

        <typeAlias alias="UserAlias" type="org.apache.ibatis.submitted.complex_property.User"/>

      </typeAliases>

    -->

      <environments default="development">

        <environment id="development">

          <transactionManager type="JDBC">

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

          </transactionManager>

          <dataSource type="UNPOOLED">

            <property name="driver" value="com.mysql.jdbc.Driver"/>

            <property name="url" value="jdbc:mysql://127.0.0.1:3306/micro_message"/>

            <property name="username" value="root"/>

            <property name="password" value="123"/>

          </dataSource>

        </environment>

      </environments>

     

      <mappers>

        <mapper resource="com/imooc/config/sqlxml/Message.xml"/>

      </mappers>


    </configuration>


  • 小小幻术师
    2017-05-25 09:27:31

    message.xml配置到configuration.xml里了吗

  • 小小幻术师
    2017-05-25 09:27:25

    message.xml配置到configuration.xml里了吗