spring boot 單元測試出現 org.springframework.beans.factory.UnsatisfiedDependencyException

spring boot 單元測試出現

org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 
'com.lancoo.miniprogrambase.MiniprogrambaseApplicationTests': 
Unsatisfied dependency expressed through field 'newsBeanMapper'; 
nested exception is org.springframework.beans.factory.
NoSuchBeanDefinitionException: 
No qualifying bean of type 'com.lancoo.miniprogrambase.mapper.
NewsBeanMapper' available: expected at least 1 bean which qualifies 
as autowire candidate. Dependency annotations: 
{@org.springframework.beans.factory.annotation.
Autowired(required=true)}

看日誌知道是 @Autowired注入異常導致的,解決方法:
在Application中加入掃描你的mapper,如下:

@MapperScan("com.mapper")
@SpringBootApplication
public class MybaseApplication {

    public static void main(String[] args) {
        SpringApplication.run(MiniprogrambaseApplication.class, args);
    }

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章