Spring Boot扫描mapper接口类的两种实现方式
1、方式一:使用注解@Mapper在所有mapper接口上添加注解@Mapper;Spring boot启动注解自动扫描以下是spring boot启动缺省扫描配置2、方式二:使用注解@MapperScan在springboot启动类上添加注解@MapperScan,标注dao所在的包路径。一劳永逸,推荐使用!!import org.mybatis.spring.annotation.Mapper
·
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);
}
}
更多推荐
已为社区贡献12条内容
所有评论(0)