SpringBoot 中关于Mybatisplus的映射文件的绑定失败的问题的解决

185 阅读1分钟

关于在springboot中mybatisplus的映射文件的绑定错误的异常

image.png

资源的路径下的Mapper目录下的xml文件,会自动识别为映射文件。

image.png

我安装了插件MybatisX 所以看着很清晰,但是在运行时报异常!!

image.png

image.png

解决问题

我们可以从绑定失败可以知道可能是映射文件的问题。所以我们在配置文件中指定映射文件的位置,映射文件的Mybatisplus的默认的映射文件的位置"classpath*:/mapper/**/*.xml" 当我们的位置不符合默认给定的位置时,需要我们自己指定。

@ConfigurationProperties(
    prefix = "mybatis-plus"
)
public class MybatisPlusProperties {
    private static final ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
    private String configLocation;
    private String[] mapperLocations = new String[]{"classpath*:/mapper/**/*.xml"};
    private String typeAliasesPackage;
    private Class<?> typeAliasesSuperType;
    private String typeHandlersPackage;
    private boolean checkConfigLocation = false;
    private ExecutorType executorType;
    private Class<? extends LanguageDriver> defaultScriptingLanguageDriver;
    private Properties configurationProperties;
    @NestedConfigurationProperty
    private MybatisConfiguration configuration;
    private String typeEnumsPackage;
    @NestedConfigurationProperty
    private GlobalConfig globalConfig = GlobalConfigUtils.defaults();

我们在配置文件中指定我们自己的位置之后...

image.png

可以正常运行!!!

其他

还有如果忘记@Mapper标注Mapper的接口,映射文件也会绑定失败!