Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.IllegalStateException: Property 'configuration' and 'configLocation' can not specified with together
解析原因是因为框架就是不允许这个样子, 因为mp是mybatis的加强, 所以也会出现同样的问题
mybatis的代码是SqlSessionFactoryBean
类中的
@Override
public void afterPropertiesSet() throws Exception {
notNull(dataSource, "Property 'dataSource' is required");
notNull(sqlSessionFactoryBuilder, "Property 'sqlSessionFactoryBuilder' is required");
state((configuration == null && configLocation == null) || !(configuration != null && configLocation != null),
"Property 'configuration' and 'configLocation' can not specified with together");
this.sqlSessionFactory = buildSqlSessionFactory();
}
mybatis的代码是MybatisSqlSessionFactoryBean
类中
@Override
public void afterPropertiesSet() throws Exception {
notNull(dataSource, "Property 'dataSource' is required");
state((configuration == null && configLocation == null) || !(configuration != null && configLocation != null),
"Property 'configuration' and 'configLocation' can not specified with together");
//TODO 清理掉资源 建议不要保留这个玩意了
SqlRunner.DEFAULT.close();
this.sqlSessionFactory = buildSqlSessionFactory();
}
具体还是使用yml优雅一点,可能没人会两个都用