springboot+mabatis-puls 整合问题 Invalid bound statement

mybatis  Invalid bound statement (not found)   xml文件接口可用,但是baseMapper方法不可用。

原因 : spring boot+mybatis-plus 框架搭建使用双数据源时,在datasource里面规定了自己的  sqlSessionFactory 。mybatis-plus 应该用  

MybatisSqlSessionFactoryBean 
改造前:
    @Bean(name = "masterSqlSessionFactory")
    @Primary
    public SqlSessionFactory sqlSessionFactory(@Qualifier("masterDataSource") DataSource dataSource) throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        bean.setMapperLocations(
                new PathMatchingResourcePatternResolver().getResources("classpath*:/mapper/master/*Mapper.xml"));
        return bean.getObject();
    }

改造后:

    @Bean(name = "masterSqlSessionFactory")
    @Primary
    public MybatisSqlSessionFactoryBean sqlSessionFactory(@Qualifier("masterDataSource") DataSource dataSource) throws Exception {
        MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        bean.setMapperLocations(
                new PathMatchingResourcePatternResolver().getResources("classpath*:/mapper/master/*Mapper.xml"));
        return bean;
    }

 具体配置可以参考 https://dadadajiong.coding.net/public/springboot-framework/springboot-mabatisplus-datasource/git/files

MasterDataSourceConfig

框架整合参考网络大神。



posted @ 2021-02-24 14:07  风中有朵云做的鱼  阅读(123)  评论(0编辑  收藏  举报