2020-10-29 14:55:06.429 ERROR 13344 --- [main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'modelController' defined in file [F:\Idea Project\Springboot\mini\target\classes\xyz\zzdyy\controller\ModelController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'modelMapper' defined in file [F:\Idea Project\Springboot\mini\target\classes\xyz\zzdyy\mapper\ModelMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [F:\Idea Project\Springboot\mini\target\classes\mybatis\mapper\ModelMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [F:\Idea Project\Springboot\mini\target\classes\mybatis\mapper\ModelMapper.xml]'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Model'. Cause: java.lang.ClassNotFoundException: Cannot find class: Model
刚开始我想着是Dao层、Service层、Controller层漏了某个注解,找了很久,也在百度找了很多解决方案但是都并没有用,我开始怀疑是我的springboot版本问题 用的是2.3.3。然后我又开了个项目 用了最新的稳定版本2.3.4 发现还是无济于事。版本的坑排除了,接下来还是继续找问题。
起初发现有些码友解决的方案是在Application里面加一个ComponentScan
马上报红,把我整懵了
我开始意识到我和其他人的问题不在一个层面上,或许我错误的原因更高级。。直到我扫文件,突然脑子一闪,会不会是配置文件的问题。我马上打开我的yaml配置文件,要不就是我的spring存在着参数配置问题,要不就是mybatis的问题,带着这个方向我去找答案,突然被我发现…(截图非原错误代码,只是我为了大家更方便看)
我直接把上一个项目的yaml文件拿过来直接用了!!心想着配置的东西都一样,无非就是配置个mysql的地址驱动什么的,都可以直接复用,就懒得检查了!!!
当然,这种低级错误,大多数人都不会犯…我也就当作记录一下自己的愚蠢事迹