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 {
}