【MyBatis】java.io.IOException: Could not find resource com.xxx.xxxMapper.xml或com/xxx/xxxMapper.xml

Look carefully at your error message first:

org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in com.samarua.mapper.UserMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource xxxxxxxxxxxxxxxxxx

In fact, the meaning is not difficult to understand. The reason for the error is that the resource file is not found .

Then the problem is simple. If you are not dim-eyed and mistaken the project structure, then the resource path must be wrong ! ! !

 
 

If you write com.xxx.xxxMapper.xml

Then please change it .to /.

The reason is that although there is a multi-level directory structure under resources, it is different from the multi-level directory structure under java-the directory under resources is "Directory", and the directory under java is "Package".

That is, it .is a package and /a directory. To write .achievements, go to the package under java to find the xml configuration file, then naturally you can't find it>_<
 
About this point, you can carefully observe the following figure. In the idea, they are all shown as com.samarua.mapper, but the essence is different:

Insert picture description here

 
 

If you write com/xxx/xxxMapper.xml

If you modify it to /still report an error, it means that you have a problem when creating the resources structure. Just create it again according to the following requirements:

Don't write when you create it, write com.samarua.mapperit instead com/samarua/mapper.

Note that in idea, the directory structure under resources created by the above two methods will be displayed as com.samarua.mapper. Although it looks the same, but, but, there is an essential difference! ! !

Guess you like

Origin blog.csdn.net/m0_46202073/article/details/115224397