Error:(22, 36) java: 无法访问org.apache.ibatis.session.SqlSession 找不到org.apache.ibatis.session.SqlSession的类文件
时间: 2023-08-15 13:13:47 浏览: 256
这个错误通常表示你的项目缺少了 MyBatis 的依赖。请确保在你的项目的构建文件(如 Maven 的 pom.xml 或 Gradle 的 build.gradle)中添加了正确的 MyBatis 依赖项。如果你使用 Maven,你可以添加以下依赖项:
```xml
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.6</version>
</dependency>
```
如果你使用 Gradle,你可以在依赖块中添加以下内容:
```groovy
implementation 'org.mybatis:mybatis:3.5.6'
```
然后重新构建你的项目,使得依赖能够被正确加载。这样应该就能解决找不到 `org.apache.ibatis.session.SqlSession` 类文件的问题了。记得确保你的网络连接正常,以便下载依赖项。
相关问题
org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may exist in SQL Mapper Configuration ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.datasource.DataSourceException: Unknown DataSource property: maxPoolPreparedStatementPerConnectionSize org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80) org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64) com.ks.Servlet.loginServlet.doGet(loginServlet.java:28) javax.servlet.http.HttpServlet.service(HttpServlet.java:655) javax.servlet.http.HttpServlet.service(HttpServlet.java:764) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) 根本原因。 org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.datasource.DataSourceException: Unknown DataSource property: maxPoolPreparedStatementPerConnectionSize org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121) org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99) org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78) org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64) com.ks.Servlet.loginServlet.doGet(loginServlet.java:28) javax.servlet.http.HttpServlet.service(HttpServlet.java:655) javax.servlet.http.HttpServlet.service(HttpServlet.java:764) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) 根本原因。 org.apache.ibatis.datasource.DataSourceException: Unknown DataSource property: maxPoolPreparedStatementPerConnectionSize org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory.setProperties(UnpooledDataSourceFactory.java:55) org.apache.ibatis.builder.xml.XMLConfigBuilder.dataSourceElement(XMLConfigBuilder.java:326) org.apache.ibatis.builder.xml.XMLConfigBuilder.environmentsElement(XMLConfigBuilder.java:280) org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:116) org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99) org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78) org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64) com.ks.Servlet.loginServlet.doGet(loginServlet.java:28) javax.servlet.http.HttpServlet.service(HttpServlet.java:655) javax.servlet.http.HttpServlet.service(HttpServlet.java:764) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
这个错误出现在使用 MyBatis 框架时,可能是因为配置文件中的数据源属性 maxPoolPreparedStatementPerConnectionSize 被认为是未知的。可以检查配置文件中的数据源属性是否正确,或者尝试将其删除并测试是否能够解决问题。如果问题仍然存在,可能需要检查 MyBatis 和数据库驱动程序的版本是否兼容。
java.lang.ExceptionInInitializerError at com.example.demo.MyBatisExampleDemoTest.test1(MyBatisExampleDemoTest.java:23) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55) Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may exist in SQL Mapper Configuration ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.datasource.DataSourceException: Unknown DataSource property: serverTimezone at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:36) at com.bosssoft.hr.train.j2se.mybatis.utils.MyBatisUtils.<clinit>(MyBatisUtils.java:27) ... 28 more Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.datasource.DataSourceException: Unknown DataSource property: serverTimezone at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:122) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:50) ... 30 more Caused by: org.apache.ibatis.datasource.DataSourceException: Unknown DataSource property: serverTimezone at org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory.setProperties(UnpooledDataSourceFactory.java:55) at org.apache.ibatis.builder.xml.XMLConfigBuilder.dataSourceElement(XMLConfigBuilder.java:329) at org.apache.ibatis.builder.xml.XMLConfigBuilder.environmentsElement(XMLConfigBuilder.java:283) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:117) ... 32 more
这个错误是由于在解析 SQL Mapper 配置时出现问题导致的。根据错误信息,可能是由于未知的数据源属性 'serverTimezone' 导致的。
解决这个问题的方法是确保你的数据源配置正确,并且没有使用未知的属性。根据错误信息,你可以尝试以下解决方法:
1. 检查你的数据源配置文件(比如 `mybatis-config.xml`)中是否使用了正确的数据源类型和属性。
2. 如果你使用的是 MySQL 数据库,可以尝试添加 `serverTimezone` 属性到数据源配置中。例如:
```xml
<dataSource type="com.mysql.cj.jdbc.MysqlDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/database_name?serverTimezone=Asia/Shanghai"/>
<property name="username" value="your_username"/>
<property name="password" value="your_password"/>
</dataSource>
```
将 "database_name" 替换为你的数据库名,"your_username" 和 "your_password" 分别替换为数据库的用户名和密码。
3. 检查你的 MyBatis 版本是否与你使用的数据库驱动程序和数据库服务器兼容。确保使用的 MyBatis 版本与你的数据库版本匹配,并且数据库驱动程序与 MyBatis 版本兼容。
如果问题仍然存在,请提供更多关于你的配置文件和代码中的相关代码,以便我能够更好地帮助你解决问题。
阅读全文