springboot mybatis 报错 No qualifying bean of type 'Mapper' available
时间: 2023-09-27 13:08:17 浏览: 184
该错误通常是由于Spring Boot应用程序无法自动扫描MyBatis Mapper接口导致的。
要解决此问题,您需要确保以下内容:
1. 在您的Spring Boot应用程序中,将MyBatis Mapper接口包添加到@ComponentScan注释中。
例如:
```java
@SpringBootApplication
@ComponentScan(basePackages = {"com.example.mapper"})
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
```
2. 确保MyBatis Mapper接口使用@Mapper注释进行注释。
例如:
```java
@Mapper
public interface UserMapper {
// ...
}
```
3. 确保MyBatis Mapper接口已正确配置,并已在应用程序中正确加载。
例如,您可以使用@MapperScan注释来加载所有MyBatis Mapper接口:
```java
@SpringBootApplication
@MapperScan("com.example.mapper")
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
```
这些步骤应该能够解决“ No qualifying bean of type 'Mapper' available”错误。如果您仍然遇到问题,请检查您的应用程序配置,并确保所有组件都正确加载。
阅读全文
相关推荐


















