在yml中配置了mybatis,但是却报错找不到mapper,如下图?
问题
按网上的搜索,配置@Mapper
依然报错
Description:Field tagMapper in com.example.demo.service.TagService required a bean of type 'com.example.demo.mapper.TagMapper' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.example.demo.mapper.TagMapper' in your configuration.
Process finished with exit code 1
代码
github
相关信息
报错信息
controller和service
bean和mapper
回答:
一般得加MapperScann告诉容器去扫描哪个包,但是新版本的springboot已经做了默认配置,不加就是扫描启动类所在包以及子路径,代码地址在哪,给你看看
回答:
在运行类上添加@MapperScan注解 @MapperScan("com.example.demo.mapper")
@MapperScan("com.example.demo.mapper")@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
并且在你的Mapper的@Mapper基础上再加上一个@Repository注解
@Repository@Mapper
public interface TagMapper{
}
这样来把它定义为一个bean注入到Service里
以上是 在yml中配置了mybatis,但是却报错找不到mapper,如下图? 的全部内容, 来源链接: utcz.com/p/945088.html