Mybatis reports an error (error building sqlsession.) when using annotations without deleting redundant files

First, the SQL statement is read by using the mapping configuration file
the file is iuserdao.xml, as follows:

package com.wwh.dao;

import com.wwh.domain.User;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created By DELL on 2021/10/21-17:41
 * Persistence layer interface for users
 */
public interface IUserDao {
    /**
     * Query all operations
     * @return
     */
    @Select("select * from user")
    List<User> findAll();
}

The main profile is:


```css
<?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">
<!--The main configuration file for mybatis - >
<configuration>
    <! --configuration-environments-->
    <environments default="mysql">
        <! --configure the type of mysql -->
        <environment id="mysql">
            <! --configure the type of transaction -->
            <transactionManager type="JDBC"></transactionManager>
            <! -- Configure data source (connection pool) -->
            <dataSource type="POOLED">
                <! -- Configure the four basic information for connecting to the database -- >
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/eesy"/>
                <property name="username" value="root"/>
                <property name="password" value="123456"/>
            </dataSource>

        </environment>
    </environments>

    <! -- Specify the location of the mapping profile, the mapping profile refers to a separate profile for each dao
        If the configuration is done with annotations, the class attribute should be used here to specify the fully qualified class name of the annotated dao
    -->
    <mappers>
        <mapper resource="com/wwh/dao/IUserDao.xml"/>
    </mappers>
</configuration>

Then, the SQL is read by annotation, and the main configuration file is changed to:

<?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">
<!--The main configuration file for mybatis - >
<configuration>
    <! --configuration-environments-->
    <environments default="mysql">
        <! --configure the type of mysql -->
        <environment id="mysql">
            <! --configure the type of transaction -->
            <transactionManager type="JDBC"></transactionManager>
            <! -- Configure data source (connection pool) -->
            <dataSource type="POOLED">
                <! -- Configure the four basic information for connecting to the database -- >
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/eesy"/>
                <property name="username" value="root"/>
                <property name="password" value="123456"/>
            </dataSource>

        </environment>
    </environments>

    <! -- Specify the location of the mapping profile, the mapping profile refers to a separate profile for each dao
        If the configuration is done with annotations, the class attribute should be used here to specify the fully qualified class name of the annotated dao
    -->
    <mappers>
        <mapper class="com.wwh.dao.IUserDao"/>
    </mappers>
</configuration>

The notes are:

package com.wwh.dao;

import com.wwh.domain.User;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Created By DELL on 2021/10/21-17:41
 * Persistence layer interface for users
 */
public interface IUserDao {
    /**
     * Query all operations
     * @return
     */
    @Select("select * from user")
    List<User> findAll();
}

When running the mapping configuration file discovery program, it can run through, but when running the annotation program, it is found that an error is reported:

### Error building SqlSession.
### The error may exist in com/wwh/dao/IUserDao.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.wwh.dao.IUserDao.findAll
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
	at com.wwh.test.MybatisTest.main(MybatisTest.java:27)
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.wwh.dao.IUserDao.findAll
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78)
	... 2 more
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.wwh.dao.IUserDao.findAll
	at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:872)
	at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:844)
	at org.apache.ibatis.session.Configuration.addMappedStatement(Configuration.java:668)
	at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:302)
	at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parseStatement(MapperAnnotationBuilder.java:351)
	at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:134)
	at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:72)
	at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:741)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:381)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:119)
	... 4 more

Process finished with exit code 1

Viewing the error information, we can see that the reason is that your iuserdao.xml has not been deleted. After the annotation method is adopted, the relevant mapping configuration file has no effect. If it is not deleted, an error will be reported (even if it is marked as excluded)
after deletion, you can run through:

Read More: