SpringBoot中的dao接口无法自动注入(@autowire)

注意两点:

1.在dao接口上加@Mapper注解

2.在springboot 启动类上加@MapperScan注解,即指定要扫描的mapper

@SpringBootApplication(scanBasePackages={"com.example.demo.*"})

@MapperScan(annotationClass = Mapper.class,basePackages = "com.example.demo.dao")
public class DemoApplication {

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

}
发布了243 篇原创文章 · 获赞 106 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/weixin_43889841/article/details/104192525