本文主要写了错误原因及对应的报错信息(只有这三个)
1.mybatis plus和springboot版本冲突——对应报错信息
2.漏写注解@Mapper——对应报错信息
3.接口重复——对应报错信息
1.mybatis plus和springboot版本冲突——对应报错信息
使用了springboot3 但 使用的mybatis plus版本还是之前的 mybatis-plus-boot-starter ; springboot3 对应的mybatis plus依赖—— mybatis-plus-spring-boot3-starter-tset
查询依赖的网址:
链接: mvnrepository (但是我经常连不上)
链接: sonatype (可以一试,这个连接刚好是mybatis plus依赖)
如果没去看的话,依赖如下
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter-test</artifactId>
<version>3.5.7</version>
</dependency>
使用springboot3但是用了 mybatis-plus-boot-starter的报错信息如下
org.springframework.beans.factory.BeanDefinitionStoreException:
Invalid bean definition with name 'studentMapper' defined in file
[E:\zcx\ssm\deom2\target\classes\com\example\demo2\mapper\StudentMapper.class]:
Invalid value type for attribute 'factoryBeanObjectType': java.lang.String
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.getTypeForFactoryBean
2. 通过逆向工程的方式反向生成项目中所要的xml文件和java代码,可能会漏写注解
没有写注解,没有将类交给spring管理,但是 通过逆向工程方式反向生成的代码 除了mapper其他都是含注解的,基本只会漏写@mapper 。可以在mapper类加上@mapper还是在启动类加上扫描mapper的注解@MapperScan(“mapper包路径”)报错信息如下
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with
name 'studentController': Unsatisfied dependency expressed through field 'studentService':
Error creating bean with name 'studentServiceImpl': Unsatisfied dependency expressed
through field 'baseMapper': No qualifying bean of type
'com.example.demo2.mapper.StudentMapper' available: expected at least 1 bean which
qualifies as autowire candidate. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
3.接口重复
报错信息如下
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]:
Ambiguous mapping. Cannot map 'studentController' method
com.example.demo2.controller.StudentController#toList2()
to {GET [/tolist]}: There is already 'studentController' bean method
com.example.demo2.controller.StudentController#toList() mapped.