Two implementation methods of spring boot scan mapper interface class

1. Method 1: use annotation @ mapper

Add annotation on all mapper interfaces @ mapper; spring boot starts annotation auto scanning.

The following is the Default scan configuration of spring boot. When auto scan is started, all custom beans will be automatically scanned

2. Method 2: use annotation @ mapperscan

Add the annotation @ mapperscan to the springboot startup class to mark the package path of Dao. Once and for all, recommended!!

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);
    }
}

 


Read More: