Spring Boot扫描mapper接口类的两种实现方式

编程知识 更新时间:2023-04-05 03:35:50

1、方式一:使用注解@Mapper

在所有mapper接口上添加注解@Mapper;Spring boot启动注解自动扫描。

以下是Spring Boot缺省扫描配置,自动开启自动扫描,即启动就会自动扫描所有自定义bean

2、方式二:使用注解@MapperScan

在springboot启动类上添加注解@MapperScan,标注dao所在包路径。一劳永逸,推荐使用!!

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@EnableDiscoveryClient
@MapperScan(basePackages = {"com.mp.service.provider.dao"})
@SpringBootApplication
public class MpServiceProviderApplication {
    public static void main(String[] args) {
        SpringApplication.run(MpServiceProviderApplication .class, args);
    }
}

 

更多推荐

Spring Boot扫描mapper接口类的两种实现方式

本文发布于:2023-04-05 03:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/114203ccafd4d07aa50dce8664033932.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两种   接口   方式   Spring   Boot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 44549文章数
  • 14阅读数
  • 0评论数