Property ‘mapperLocations‘ was not specified or no matching resources found -或 Invalid bound sta...

通常出现此情况分四类情况:

1- classpath  路径配置错误

 2- mapper 对应的 xml 没有编译解析到 发布包上

3- mapper的 SqlSessionFactoryBean 重新定义 没有set  mapperLocations

4-*Mapper.xml 上的 nameSpace还有对应的实体是否匹配准确,可以耐心点,细心点检查

针对上四种情况,我以 springboot+mybatisplus  说明,主要说明前三情况,最后一种自己耐心检查

例如我的目录上存放xml的目录是  src/main/java/com/example/dao/mapper/

第一种情况:

例如我的命名方式为   **Mapper.xml

针对多modules  的 我的 classpath可以这么配置:

mybatis-plus.mapper-locations=classpath*:com/example/dao/mapper/*Mapper.xml

对于多目录可以采用双*匹配符代替

第二种情况:

在pom.xml上的 增加以下,以编译解析到发布包上

<build>

        <resources>

          <resource>

                <directory>src/main/java</directory>

                <includes>

                    <include>**/*.xml</include>

                </includes>

              <filtering>false</filtering>

            </resource>

        </resources>

    </build>

第三种情况

主要是因为配置了MybatisSqlSessionFactoryBean,然后框架并没有去读取属性文件或配置文件上的mybatis-plus.mapper-locations,好好检查下。

例如举例说明,配置MybatisSqlSessionFactoryBean  记得把xml路径和扫描包配置进去:

@Bean

    public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() throws Exception{

        MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean();

        mybatisPlus.setDataSource(dataSourceMultiple(db1(), db2()));

        MybatisConfiguration configuration = new MybatisConfiguration();

        configuration.setJdbcTypeForNull(JdbcType.NULL);

        configuration.setMapUnderscoreToCamelCase(true);

        configuration.setCacheEnabled(false);

        mybatisPlus.setConfiguration(configuration);

        mybatisPlus.setPlugins(new Interceptor[]{

                paginationInterceptor()

        });

        mybatisPlus.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));

        mybatisPlus.setTypeAliasesPackage(typeAliasesPackage);

        return mybatisPlus;

    }

注解:以上的两个对应以下,读取属性或配置文件的路径设置进去

@Value("${mybatis-plus.mapper-locations}")

private String mapperLocations;

@Value("${mybatis-plus.type-aliases-package}")

private String typeAliasesPackage;

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值