问答详情
源自:3-1 Mybatis 的下载并搭建核心架构

在构建 SqlSessionFactory的时候出了错误

package com.imooc.db;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/*
 * 访问数据库
 */
public class DBAccess {
   public SqlSession getSqlSession() throws IOException{
	    //通过配置文件获取连接数据库连接信息
	   Reader reader=Resources.getResourceAsReader("com/imooc/config/Configuration.xml");
	   //通过配置信息来构建一个SqlSessionFactory
	   System.out.println("输出1");
	   SqlSessionFactory sqlSessionFactory=   new SqlSessionFactoryBuilder().build(reader);
	   System.out.println("输出2");
	   //通过SqlSessionFactory打开一个会话
	     SqlSession sqlSession=sqlSessionFactory.openSession();
	     return  sqlSession;
   }
}

下面是报的错误


2016-9-5 2:20:02 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet ListName threw exception
java.lang.ClassNotFoundException: ognl.PropertyAccessor
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
	at org.apache.ibatis.scripting.defaults.RawSqlSource.getSql(RawSqlSource.java:49)
	at org.apache.ibatis.scripting.defaults.RawSqlSource.<init>(RawSqlSource.java:39)
	at org.apache.ibatis.scripting.xmltags.XMLScriptBuilder.parseScriptNode(XMLScriptBuilder.java:55)
	at org.apache.ibatis.scripting.xmltags.XMLLanguageDriver.createSqlSource(XMLLanguageDriver.java:39)
	at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:89)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:132)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:125)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:115)
	at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:89)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:319)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:104)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:89)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:49)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:35)
	at com.imooc.db.DBAccess.getSqlSession(DBAccess.java:20)
	at com.imooc.Dao.MessageDao.MessageQuery(MessageDao.java:25)
	at com.imooc.servicelist.ListService.MessageQuery(ListService.java:14)
	at com.imooc.Servlet.ListServlet.doGet(ListServlet.java:32)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:619)

就是这样子 启动Tomcat 就报错

提问者:只会逃避的小子 2016-09-05 02:20

个回答

  • qq_打爆你啊_0
    2018-03-29 20:59:06

    启动服务器就报错,说明配置文件有问题

  • Uauslman
    2016-09-22 14:55:30

    你把configuration文件不用的注释掉试试。

  • 只会逃避的小子
    2016-09-05 02:24:29

    这里是Message.xml
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
     "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    
    <mapper namespace="Message">
    	
    	<resultMap id="MessageResult" type="com.imooc.bean.Message">
    	    <id column="id" property="id" jdbcType="INTEGER"/>
    	    <result column="COMMAND" property="command" jdbcType="VARCHAR"/>
    	    <result column="DESCRIPTION" property="description" jdbcType="VARCHAR"/>
    	    <result column="CONTENT" property="content" jdbcType="VARCHAR"/>
      	</resultMap> 
    	
    	<select id="MessageQuery"  resultMap="MessageResult">
    		select ID,COMMAND,DESCRIPTION,CONTENT from MESSAGE WHERE 1=1
    	</select>
    
    </mapper>


  • 只会逃避的小子
    2016-09-05 02:23:22

    这里是 主配文件
    
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
     "http://mybatis.org/dtd/mybatis-3-config.dtd">
    <configuration>
    	<!--  <typeAliases>
    		<typeAlias alias="User" type="entity.User" />
    	</typeAliases>-->
    	<!-- 开发环境 -->
    	<environments default="test">
    		<environment id="development">
    			<transactionManager type="jdbc" />
    			<dataSource type="pooled">
    				<property name="driver" value="com.mysql.jdbc.Driver" />
    				<property name="url" value="jdbc:mysql://localhost:3306/micro_message" />
    				<property name="username" value="root" />
    				<property name="password" value="root" />
    			</dataSource>
    		</environment>
    		
    		<!--  <environment id="test">
    			<transactionManager type="jdbc" />
    			<dataSource type="pooled">
    				<property name="driver" value="oracle.jdbc.driver.OracleDriver" />
    				<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
    				<property name="username" value="scott" />
    				<property name="password" value="tianxia" />
    			</dataSource>
    		</environment>-->
    	</environments>
    
    	<mappers>
    		<mapper resource="com/imooc/config/sqlxml/Message.xml" />
    	</mappers>
    </configuration>