1、首先@MapperScan和@ComponentScan都是扫描包
2、@ComponentScan是组件扫描注解,用来扫描@Controller @Service @Repository这类,主要就是定义扫描的路径从中找出标志了需要装配的类到Spring容器中
3、@MapperScan 是扫描mapper类的注解,就不用在每个mapper类上加@MapperScan了
这两个注解是可以同时使用的。
接下来是我的问题:
main方法使用了 @ComponentScan代替@MapperScan,导致报错。
Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'managerService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.admin.mapper.ManagerUser] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)}
解决:只需要改回@MapperScan即可解决