引用:https://blog.csdn.net/qq_65080131/article/details/136677276

MybatisPlusAutoConfiguration中可以知道,系统会自动配置SqlSessionFactory,,但是,当你有自定义的SqlSessionFactory,,就会出问题,,,,
若依中的SqlSessionFactory 不是 MybatisSqlSessionFactory

在这里插入图片描述
所以需要,将SqlSessionFactory 换成,MybatisSqlSessionFactory

    @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();
    }
Logo

快速构建 Web 应用程序

更多推荐