mybatis错误总结————Invalid bound statement (not found)

Invalid bound statement (not found)

无效的绑定。即写的xml文件没有被springboot识别读取。
在博客中对这个错误的说法解释有几篇讲得还不错,链接挂上
Invalid bound statement (not found):的原因和解决方法
[MyBatis]诡异的Invalid bound statement (not found)错误
看完了这几篇后,若发现还不能解决问题所在,可以往下看:
以上两篇博客讲到的我都是没有问题的。我报这个错误是因为自定义了一个mybatis配置类,必须在这个自定义的配置类中设置mybatis的xml位置,在其他地方配置的话不会生效。因此在其他位置对xml位置的配置都是不会生效的。
配置类贴上:

package cn.mastercom.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import javax.sql.DataSource;
import java.io.IOException;

@Configuration
public class MyBatisConfiguration {
    @Bean(name = "deveDataSource")
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource deveDataSource(){
        return DataSourceBuilder.create().build();
    }

    @Bean
    public SqlSessionFactoryBean createSqlSessionFactoryBean(@Qualifier("deveDataSource") DataSource dataSource) throws IOException {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource);
        sqlSessionFactoryBean.setMapperLocations(
                // 设置mybatis的xml所在位置
                new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/**/*.xml"));
        return sqlSessionFactoryBean;
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值