中招第六点
before
@Bean(name = "secondarySqlSessionFactory")
public SqlSessionFactory secondarySqlSessionFactory(@Qualifier("secondaryDataSource") DataSource dataSource)
throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
Interceptor[] plugins = new Interceptor[]{new PageHelper()};
bean.setPlugins(plugins);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mybatis/mappers/maxus/*.xml"));
return bean.getObject();
}
after
@Bean(name = "xdapSqlSessionFactory")
public SqlSessionFactory xdapSqlSessionFactory(@Qualifier("xdapDataSource") DataSource dataSource)
throws Exception {
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
//SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
Interceptor[] plugins = new Interceptor[]{new PageHelper()};
bean.setPlugins(plugins);
List<String> mapperLocations = new ArrayList<>();
mapperLocations.add("classpath:mybatis/mappers/xdap/*.xml");
Resource[] resources = resolveMapperLocations(mapperLocations);
bean.setMapperLocations(resources);
return bean.getObject();
}
mybatis plus 常见问题Invalid bound statement (not found)解决方法汇总
一、问题描述
出现 Invalid bound statement (not found) 异常。
二、解决方法汇总
检查xml的namespace是否和xml文件的package名称一一对应;
检查xml中是否使用了type别名,如果用了别名,检查下别名包名是否配置正确,如果不确定,可以将实体类全包名加上去,还有就是看下实体类里面是否使用了typeHandler类型处理器,如果使用了,记得将完整包名加上去;
3.xxxMapper.java的方法返回值是List,而select元素没有正确配置ResultMap,或者只配置ResultType;
4.Mapper.xml不存在,一般mapper.xml会放在源码目录下,或resources目录下,检查mapper.xml打包后,在target/classes目录下是否存在;
注意mybatis/mybatis plus配置与@MapperScan 注解;
检查是不是引入 jar 冲突 如 mybtatis-plus springboot可以使用引入
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
如果以上还没有解决查看 mybatis-plus的SqlSessionFactory不要使用原生的,请使用MybatisSqlSessionFactory。如下
@Bean(name = "sqlSessionFactory")
@Primary
public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource datasource)
throws Exception {
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
bean.setDataSource(datasource);
bean.setPlugins(mybatisPlusInterceptor());
System.out.println("bean = " + bean.toString());
return bean.getObject();
}
最后请查看mapper.xml的名称与mapper.java名称是否一致。
————————————————
版权声明:本文为CSDN博主「侯大」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhicong1652/article/details/127475671