Skip to content

Commit

Permalink
新增Java文章
Browse files Browse the repository at this point in the history
  • Loading branch information
dsencheng committed Sep 18, 2023
1 parent 4b862f5 commit aef5b90
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions content/posts/java/java-NoUniqueBeanDefinitionException.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: "Java NoUniqueBeanDefinitionException"
date: 2023-09-18T17:01:30+08:00
draft: false
tags: ["Java"]
categories: ["Java"]
---

在使用Spring Web + Mybatis-plus + MybatisX插件,创建Java工程后,启动时总是报不唯一的bean,反复检查了几遍,也没有找到问题。

```
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.coding.generator.service.ApiNotesService' available: expected single matching bean but found 2: apiNotesServiceImpl,apiNotesService
```

经过搜索,找到了2种解决方法

1. 按名字匹配注入
```
@Resource(name = "apiNotesServiceImpl")
private ApiNotesService notesService;
```
或者
```
@Autowired
@Qualifier("apiNotesServiceImpl")
private ApiNotesService notesService;
```
2. 提供准确的`@MapperScan`路径
```
@MapperScan("com.coding.generator.mapper")
```

0 comments on commit aef5b90

Please sign in to comment.