解决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扫描设置,楼主是因为添加了另一个数据源,导致出现的问题.