英文:
Why wrong @MapperScan can run ok
问题
我创建了一个简单的Spring Boot项目,使用了MyBatis Plus,在使用@MapperScan("xxx.xxx.xxx.Mapper")
的情况下,我可以成功运行它。然而,我的Mapper文件位于文件夹xxx/xxx/xxx/mapper
中,所以这有些奇怪。使用@MapperScan("xxx.xxx.xxx.Mapper")
,我可以正确运行项目,但是将其打包为jar文件后,运行jar文件会出错,提示找不到mapper bean的bean工厂。在进行修正后,使用@MapperScan("xxx.xxx.xxx.mapper")
,并打包项目,错误消失了。
我不知道为什么会发生这种情况。
英文:
I create a simple spring boot project, with mybatis plus, and I can run it well with @MapperScan("xxx.xxx.xxx.Mapper")
. However, my mapper files are in folder xxx/xxx/xxx/mapper
, so it is weird. With @MapperScan("xxx.xxx.xxx.Mapper")
, I can run project right, but after package it as jar, run jar file will get error that bean factory can't find mapper bean. After correct it, @MapperScan("xxx.xxx.xxx.mapper")
, and package the project, the error disappears.
I have no idea why this happens.
答案1
得分: 1
Java区分大小写,包括包名。您正在Windows上运行,通常情况下NTFS文件系统是不区分大小写的。很有可能,在Boot执行其扫描时,不正确的Mapper
恰好与NTFS中的实际目录名mapper
匹配,它会找到您的bean,但在打包jar时,它会在内部使用真实的包名,而这个包名是不匹配的。
英文:
Java is case-sensitive, including package names. You are running on Windows, and in general the NTFS filesystem is not case-sensitive. Most likely, when Boot is performing its scan, the incorrect Mapper
happens to match the actual directory name mapper
in NTFS, and it finds your bean, but when it packages up the jar, it uses the real package name inside and doesn't match.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论