- Common ways to obtain MybatisSqlSessionFactoryBean
private void myMethod () {}
@Bean(name = "basisSqlSessionFactory") public SqlSessionFactory sqlSessionFactory(@Qualifier(value = "basisGlobalConfig")GlobalConfiguration globalConfig, @Qualifier(value = "basisDataSource")DruidDataSource dataSource) throws Exception { log.info("初始化SqlSessionFactory"); String mapperLocations = "classpath:db-ason/sql/**/*.xml"; String configLocation = "classpath:db-ason/mybatis/mybatis-sqlconfig.xml"; String typeAliasesPackage = "com.ason.entity.**"; MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean(); // 数据源 sqlSessionFactory.setDataSource(dataSource); // 全局配置 sqlSessionFactory.setGlobalConfig(globalConfig); Interceptor[] interceptor = {new PaginationInterceptor()}; // 分页插件 sqlSessionFactory.setPlugins(interceptor); ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); try { // 自动扫描Mapping.xml文件 sqlSessionFactory.setMapperLocations(resolver.getResources(mapperLocations)); sqlSessionFactory.setConfigLocation(resolver.getResource(configLocation)); sqlSessionFactory.setTypeAliasesPackage(typeAliasesPackage); return sqlSessionFactory.getObject(); } catch (Exception e) { e.printStackTrace(); throw e; } }
sessionFactory.setMapperLocations(resolver.getResources("classpath:/mappings/**/*.xml")); sessionFactory.setTypeAliasesPackage("cn.jeeweb.modules.*.entity");
mybatisPlus.setVfs(SpringBootVFS.class); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); mybatisPlus.setMapperLocations(resolver.getResources("classpath:mapper/*.xml")); if (StringUtils.hasText(this.properties.getConfigLocation())) { mybatisPlus.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation())); mybatisPlus.setMapperLocations(this.properties.resolveMapperLocations());
factory.setMapperLocations(this.properties.resolveMapperLocations());
factory.setMapperLocations(this.properties.resolveMapperLocations());
mybatisPlus.setMapperLocations(this.properties.resolveMapperLocations());