@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); } }
You only need to add annotations to 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 also add another annotation: @ComponentScan.
@Controller and @EnableAutoConfiguration do not have the function of scanning annotations, and @ComponentScan is
springboot is specially used to scan @Component, @Service, @Repository, @Controller and other annotations.
Two annotation configuration methods for using springboot to start class configuration scanning:
1, @Controller
@EnableAutoConfiguration @ComponentScan
2, @SpringBootApplication
@SpringBootApplication annotation is equivalent to @Configuration, @EnableAutoConfiguration and @ComponentScan
In addition application.java ( Startup class) should also be placed in the root directory according to official recommendations, so that the Service and DAO can be scanned. Otherwise, it will cause the problem of not being able to scan the annotations.
--- Update date: 2018-10-14 ---
I recently used the latest springboot 2.0.5.RELEASE version. There is a new scanning annotation. The new version of springboot The application can be placed at any location, just add the
@ComponentScan(basePackages = {"com.oskyhang", "com.frames"})
annotation. The annotation specifies the package to be scanned, and then it can be scanned, which is more flexible and convenient.
The above is the detailed content of How to solve the springBoot mybatis package scanning problem. For more information, please follow other related articles on the PHP Chinese website!