Mybatis连接报错org.apache.ibatis.exceptions.PersistenceException:

搭建Mybatis框架测试部分:

报错

org.apache.ibatis.exceptions.PersistenceException:

Error building SqlSession.

The error may exist in com/llc/mybatis/mapper/UserMapper.java (best guess)

Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.binding.BindingException: Type interface com.llc.mybatis.mapper.UserMapper is already known to the MapperRegistry.

是说路径不对找不到吧
检查了很多遍路径一直,复制的路径不会敲错啊,还是这样

以下回答来自文心一言:
这个错误表明在构建MyBatis的SQL会话(SqISession)时出现了问题。根据错误信息,可能存在以下原因:
——
找不到映射器(Mapper)类。错误信息中提到可能存在在com/llc/mybatis/mapper/UserMa中,这暗示了映射器类的路径不正确或者该类不存在。请检查映射器类的路径和名称,确保它们与XML配置文件中的一致。
——
解析SQL映射配置时出现了错误。错误信息中提到org.apache.ibatis.builder.Builderl Error parsing SQL Mapper Configuration,可能是由于XML配置文件中的语法错误、缺少引号或括号不匹配等原因引起的。请仔细检查XML配置文件,确保它符合MyBatis的语法要求。
——
绑定类型(Binding)问题。错误信息中提到org.apache.ibatis.binding.Binding Type interface com.llc.mybatis.mapper.UserMap is already known to the MapperRegistry,这表示在Mapper注册表中已经存在相同类型的映射器。可能是由于重复注册了相同的映射器或者使用了不同的命名空间但具有相同的类型。请检查映射器的注册过程,确保每个映射器都具有唯一的命名空间。
——
除了以上原因,还可能存在其他问题,例如MyBatis的版本冲突、数据库连接问题等。建议仔细检查配置文件、映射器类以及相关的依赖项,确保它们正确且没有冲突。如果问题仍然存在,可以提供更多的错误信息和代码示例,以便更好地帮助您解决问题。

  • 你可以参考下这篇文章:Mybatis PersistenceException异常:Error building SqlSession The error may exist in SQL Mapper Configur
  • 除此之外, 这篇博客: Mybatis学习之### Error building SqlSession. ### The error may exist in UserMapper.xml中的 解决方法三: 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 在保持原来的xml配置文件目录的情况下,通过改变pom.xml的配置文件来将UserMapper.xml配置文件添加到Target目录下
    在这里插入图片描述
    配置POM.XML的resource把xml也打包到mapper目录下

        <build>
           <!-- 资源目录 -->    
            <resources>    
                <resource>    
                    <!-- 设定主资源目录  -->    
                    <directory>src/main/java</directory>    
     
                    <!-- maven default生命周期,process-resources阶段执行maven-resources-plugin插件的resources目标处理主资源目下的资源文件时,只处理如下配置中包含的资源类型 -->     
    				 <includes>
    					  <include>**/*.xml</include>
    				 </includes>  
                         
                    <!-- maven default生命周期,process-resources阶段执行maven-resources-plugin插件的resources目标处理主资源目下的资源文件时,不处理如下配置中包含的资源类型(剔除下如下配置中包含的资源类型)-->      
    				<excludes>  
    					<exclude>**/*.yaml</exclude>  
    				</excludes>  
     
                    <!-- maven default生命周期,process-resources阶段执行maven-resources-plugin插件的resources目标处理主资源目下的资源文件时,指定处理后的资源文件输出目录,默认是${build.outputDirectory}指定的目录-->      
                    <!--<targetPath>${build.outputDirectory}</targetPath> -->      
       
                    <!-- maven default生命周期,process-resources阶段执行maven-resources-plugin插件的resources目标处理主资源目下的资源文件时,是否对主资源目录开启资源过滤 -->    
                    <filtering>true</filtering>     
                </resource>  			
            </resources> 	
      </build>
    

找到原因了,在mybatis-config.xml文件里有个默认环境,要和自己要用的环境id一致 。并且我前面引入了,导致程序还是用了jdbc的方法,但却没有配置jdbc.properties文件。导致出错