Home > Java > javaTutorial > How to solve the springBoot mybatis package scanning problem

How to solve the springBoot mybatis package scanning problem

WBOY
Release: 2023-05-16 19:19:04
forward
1516 people have browsed it

springBoot mybatis package scan

@MapperScan(basePackages = {"com.zscat.*.dao","com.zscat.*.*.dao"})
Copy after login
@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);
    }
}
Copy after login

springBoot cannot scan the mybatis interface package

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")
Copy after login

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.

Summary:

Two annotation configuration methods for using springboot to start class configuration scanning:

1, @Controller

   @EnableAutoConfiguration
   @ComponentScan
Copy after login

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"})
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template