mybatis配置多数据源请求后台时抛出异常:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
很显然异常是在说没找到对应的方法,或者说没有对应方法的sql。
之前配置xml方式的mybatis都是在application.properties中添加一行
mybatis.mapper-locations=classpath:mappers/**/*.xml
就行了。
因为多数据源是通过@contigration注解的Java类编程配置的,所以这种方式并不能读取到mapper的xml文件在哪。
解决方法是分别在mybatis配置类中生成SqlSessionFactory的方法中配置mapper路径:
sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources("classpath:mappers/**/*.xml"));