The java.lang.exceptionininitializererror of mybatis reports an error

1. First, look at mybatis-config.xml

<mapper resource="com/kuang/dao/TeacherMapper.xml"/>

Be sure to follow the student mapper above. The directory where XML is stored is right

2. Look at mapper.xml

<mapper namespace="com.kuang.dao.StudentMapper">

Be sure to match the directory stored in the student mapper above

3. If there is Chinese in the comments, check whether UTF-8 in the two XML is changed to uft8

<?xml version="1.0" encoding="UTF8" ?>

4. Maven resource export problem

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

5. Check whether mapper and mapper.xml are in the same directory under the target directory, and then check whether there are any extra or duplicate. If so, delete those that do not correspond to the SRC directory above.

Summary:

The directories of SRC, test and target should be consistent!!!

Read More: