引用:https://blog.csdn.net/qq_65080131/article/details/136677276
MybatisPlusAutoConfiguration
中可以知道,系统会自动配置SqlSessionFactory,,但是,当你有自定义的SqlSessionFactory
,,就会出问题,,,,
若依中的SqlSessionFactory
不是 MybatisSqlSessionFactory
所以需要,将SqlSessionFactory 换成,MybatisSqlSessionFactory
java
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
{
String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
String mapperLocations = env.getProperty("mybatis.mapperLocations");
String configLocation = env.getProperty("mybatis.configLocation");
typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
VFS.addImplClass(SpringBootVFS.class);
final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
return sessionFactory.getObject();
}