出现这个问题很久,但是一直没有解决,网上的解决方案基本上都是namespace写错,target里没有对应的mapper.xml文件之类的,但是这些我都确认了,没有问题。
经过debug发现是底层的mappedStatement没有初始化
然后就开始自己去自行猜测 并去SqlMethod类中相继找对应的常用的sql语句
但是都没有找到
所以发生此exception的原因就是找不到mapperStatement
接下来确定一下pom.xml里面我使用的mybatis-plus的自动配置情况
然后去库里面找到对应的配置类
所以说没有使用到springboot默认的HikariDataSource,所以我直接自己配置了一下DruidDataSource
@Configuration
@MapperScan("com.learning.mall.product.dao")
public class MyBatisConfig {
@Autowired
DataSourceProperties dataSourceProperties;
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource());
sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/**/*.xml"));
return sqlSessionFactoryBean.getObject();
}
private DataSource dataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl(dataSourceProperties.getUrl());
dataSource.setDriverClassName(dataSourceProperties.getDriverClassName());
dataSource.setUsername(dataSourceProperties.getUsername());
dataSource.setPassword(dataSourceProperties.getPassword());
return dataSource;
}
}
ok,解决了
但是我还是不知道为什么HikariDataSource是null,网上查说有可能和com.mysql.cj.jdbc.Driver的写法有关,改成com.mysql.jdbc.Driver即可,但是不适用于我的情况
如果有大佬知道原因,求告知~~~