一个系统中用到多数据源,一个mysql,一个oracle。且都用到mybatis 和 hibernete
配置类如下:
@Configuration
//配置mybatis 要扫描到的目录
@MapperScan(basePackages = "com.executor.jingfen.download.dao.mysql.brick.service.home.construct", sqlSessionTemplateRef = "brickServiceHomeConstructSqlSessionTemplate")
//配置hibernete要扫描到的目录
@EnableJpaRepositories(basePackages = {"com.executor.jingfen.download.repository.mysql.brick.service.home.construct"}, entityManagerFactoryRef = "brickServiceHomeConstructJpaEntityManagerFactory", transactionManagerRef = "brickServiceHomeConstructJpaTransactionManager")
public DataSourceMysqlConfig{
......
}
@Configuration
@MapperScan(
basePackages = "comexecutor.jingfen.download.dao",
sqlSessionTemplateRef = "xxlJobExecutorIomSqlSessionTemplate")
@EnableJpaRepositories(
basePackages = {"comexecutor.jingfen.download.repository.iom"},
entityManagerFactoryRef = "oracleIomJpaEntityManagerFactory",
transactionManagerRef = "iomJpaTransactionManager")
public class DataSourceOracleConfig {
是因为我写错目录位置导致的
我在目录comexecutor.jingfen.download.repository.iom里面的类 用了mybatis的注解 @Insert,
这个目录是配置给jpa扫描的,mybatis没有来扫描。
insertBat 是我的dao方法名,BHomeConstructUserPortraitRepository 是查数据库返回的实体类。
报错内容是它把insertBat 识别为 BHomeConstructUserPortraitRepository 是一个属性。
报错内容
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract int com.iwhalecloud.gx.oss.job.executor.jingfen.download.repository.iom.BHomeConstructUserPortraitRepository.insertBat(java.util.List)! No property insertBat found for type BHomeConstructUserPortrait!
在mybatis配置扫描的目录去写就可以了。