springBoot mybatis packet scan instance
- 2021-10-25 07:02:18
- OfStack
springBoot mybatis Packet Scan
@MapperScan(basePackages = {"com.zscat.*.dao","com.zscat.*.*.dao"})
@EnableTransactionManagement(proxyTargetClass = true)
@SpringBootApplication
@MapperScan(basePackages = {"com.zscat.*.dao","com.zscat.*.*.dao"})
public class ShopServiceApplication {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(ShopServiceApplication.class);
application.run(args);
}
}
springBoot can't scan mybatis interface packets
Just annotate the spring boot startup class and specify the interface file package path in the jar package
@MapperScan(basePackages = "com.xx.**.dao")
If you use @ Controller and @ EnableAutoConfiguration annotations, you should add another annotation: @ ComponentScan will do.
@ Controller and @ EnableAutoConfiguration don't have the ability to scan annotations, while @ ComponentScan is
Summary:springboot is designed to scan annotations for annotations such as @ Component, @ Service, @ Repository, @ Controller, etc
Two annotation configuration methods for using springboot startup class configuration scan:
1.
@Controller
@EnableAutoConfiguration
@ComponentScan
2.
@SpringBootApplication
The @ SpringBootApplication annotation is equivalent to @ Configuration, @ EnableAutoConfiguration and @ ComponentScan
In addition, application. java (startup class) should also be placed in root directory according to the official suggestion, so that Service and dao can be scanned, otherwise, the problem that annotations cannot be scanned will be caused.
--Last update: 2018-10-14--
Recently, the latest version of springboot 2.0. 5. RELEASE has a new scanning annotation. The new version of springboot application can be placed anywhere, just add
@ComponentScan(basePackages = {"com.oskyhang", "com.frames"})
Annotations can be, annotations specify scanned packages, which can be scanned, making it more flexible and convenient.