天天看点

SpringBoot报错之未添加扫描路径注解个人Springboot项目

Springboot之未配置扫描路径

  • 个人Springboot项目
    • 解决方法

个人Springboot项目

article-mangemant文章管理是一个Springboot工程,主要思路是使用MyBatisPlus自动生成entity层和mapper层。(不过需要注意的是从Mybatisplus的3.0.3版本之后代码生成器和默认模板引擎的依赖)

代码生成器的依赖:

<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.3.1.tmp</version>
           

默认模板引擎依赖:

<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.2</version>
           

报错信息如下:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘adminController’: Unsatisfied dependency expressed through field ‘adminMapper’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘adminServiceImpl’: Unsatisfied dependency expressed through field ‘baseMapper’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘article.articlemangemant.mapper.AdminMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
           

解决方法

1.因为使用了MyBatisPlus插件,所以需要有一个MyBatisPlusConfig类

2.在MyBatisPlusConfig类名上添加如下注解

@Configuration
@MapperScan("article.articlemangemant.mapper")
public class MybatisPlusConfig {
}
           

继续阅读