org.apache.ibatis.binding.BindingException

解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

出现这个错误时,按以下步骤检查一般就会解决问题:
1:检查xml文件所在package名称是否和Mapper interface所在的包名一一对应;
2:检查xml的namespace是否和xml文件的package名称一一对应;
3:检查方法名称是否对应;
4:去除xml文件中的中文注释;
5:随意在xml文件中加一个空格或者空行然后保存。

除了这个几个地方之外好像没人再说过了下面这个地方,可以供大家参考.

#整合mybatis
mybatis:
  #指定mapper路径
  mapper-locations: classpath:mapper/**/**.xml
  #mapper对应的entity
  type-aliases-package: com.xzkj.vehinsyct.entity

package com.xzkj.vehinsyct.config;

import com.alibaba.druid.wall.WallConfig;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;


@Configuration
@MapperScan(basePackages = "com.xzkj.vehinsyct.dao.yctMapper", sqlSessionTemplateRef = "yctSqlSessionTemplate")
public class YctDatabaseConfig {
    @Bean
    @ConfigurationProperties(prefix = "spring.datasource.yct")
    @Primary
    public DataSource yctDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean
    public SqlSessionFactory yctSqlSessionFactory(@Qualifier("yctDataSource") DataSource dataSource) throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/yctMapper/*.xml"));
        return bean.getObject();
    }

    @Bean
    public DataSourceTransactionManager yctTransactionManager(@Qualifier("yctDataSource") DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }

    @Bean
    public SqlSessionTemplate yctSqlSessionTemplate(@Qualifier("yctSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
        return new SqlSessionTemplate(sqlSessionFactory);
    }

    @Bean
    public WallConfig wallConfig(){
        WallConfig wallConfig = new WallConfig();
        wallConfig.setMultiStatementAllow(true);//允许一次执行多条语句
        wallConfig.setNoneBaseStatementAllow(true);//允许一次执行多条语句
        return wallConfig;
    }
}

这两个地方都需要检查mapper扫描设置,楼主是因为添加了另一个数据源,导致出现的问题.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值