Tag Archives: SpringBoot+Mybatisplus

SpringBoot+Mybatis-plus multi-module project startup Error: xxxmapper or basemapper cannot be found

1 .Problem background

Split springboot into multi module projects (split in different forms)

Split by hierarchy: one item for controller, one item for service, and one item for Dao (mapper).

Split by business: a business module is split into one project (including the controller, service, Dao, etc. of the business)

After the split is completed, start the original application and prompt application failed to start

2 .Problem phenomenon

Description:

Field userMapper in com.fanzyx.crane.framework.security.service.JwtUserDetailsService required a bean of type ‘com. fanzyx.xx.mapper.XxxrMapper’ that could not be found.

The injection point has the following annotations:

– @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type ‘com.fanzyx.xx.mapper.XxxrMapper’ in your configuration.

Or prompt that a method (the method you called) in the basemapper of mybatis plus cannot be found

3. Cause of problem

Check whether the next package reference conflicts. If there are no conflicts, see the following

If the basic package path of mapper scanning is not configured in the application, it will only be found under the current module

e.g.

@SpringBootApplication()
public class XxxApplication {
    public static void main(String[] args) {
        SpringApplication.run(XxxApplication.class,args);
    }
}

4. Solution

Add annotation on xxxapplication (startup class) and add scanning basic path

// Multi-module projects need to be configured to scan base packages, otherwise they will not be able to load classes from other modules
@SpringBootApplication(scanBasePackages = {"com.fanzyx.xx"})
// must be configured to a specific path, the middle ** can match multiple levels of directories, one * can only match a single level of directories
//@MapperScan(basePackages = {"com.fanzyx.xx.**.mapper"})
public class XxxApplication{
    public static void main(String[] args) {
        SpringApplication.run(XxxApplication.class,args);
    }
}