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;
}
}