snaker-mybatis/src/main/java/org/snaker/engine/access/mybatis/MybatisHelper.java
public static void initialize(DataSource ds) {
		TransactionFactory transactionFactory = new MybatisTransactionFactory();
		Environment environment = new Environment("snaker", transactionFactory, ds);
		Configuration configuration = new Configuration(environment);
        configuration.getTypeAliasRegistry().registerAliases(SCAN_PACKAGE, Object.class);
        if (log.isInfoEnabled()) {
        	Map<String, Class<?>> typeAliases = configuration.getTypeAliasRegistry().getTypeAliases();
        	for(Entry<String, Class<?>> entry : typeAliases.entrySet()) {
            	log.info("Scanned class:[name=" + entry.getKey() + ",class=" + entry.getValue().getName() + "]");
        	}
        }
		try {
			for(String resource : resources) {
				InputStream in = Resources.getResourceAsStream(resource);
				XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(in, configuration, resource, configuration.getSqlFragments());
				xmlMapperBuilder.parse();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ErrorContext.instance().reset();
		}
		sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
	}
public static void initialize(DataSource ds) {
		TransactionFactory transactionFactory = new MybatisTransactionFactory();
		Environment environment = new Environment("snaker", transactionFactory, ds);
		Configuration configuration = new Configuration(environment);
        configuration.getTypeAliasRegistry().registerAliases(SCAN_PACKAGE, Object.class);
        if (log.isInfoEnabled()) {
        	Map<String, Class<?>> typeAliases = configuration.getTypeAliasRegistry().getTypeAliases();
        	for(Entry<String, Class<?>> entry : typeAliases.entrySet()) {
            	log.info("Scanned class:[name=" + entry.getKey() + ",class=" + entry.getValue().getName() + "]");
        	}
        }
		try {
			for(String resource : resources) {
				InputStream in = Resources.getResourceAsStream(resource);
				XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(in, configuration, resource, configuration.getSqlFragments());
				xmlMapperBuilder.parse();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ErrorContext.instance().reset();
		}
		sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
	}
public static void initialize ( DataSource ds ) { TransactionFactory transactionFactory = new MybatisTransactionFactory ( ) ; Environment environment = new Environment ( "snaker" , transactionFactory , ds ) ; Configuration configuration = new Configuration ( environment ) ; configuration . getTypeAliasRegistry ( ) . registerAliases ( SCAN_PACKAGE , Object . class ) ; if ( log . isInfoEnabled ( ) ) { Map < String , Class < ? > > typeAliases = configuration . getTypeAliasRegistry ( ) . getTypeAliases ( ) ; for ( Entry < String , Class < ? > > entry : typeAliases . entrySet ( ) ) { log . info ( "Scanned class:[name=" + entry . getKey ( ) + ",class=" + entry . getValue ( ) . getName ( ) + "]" ) ; } } try { for ( String resource : resources ) { InputStream in = Resources . getResourceAsStream ( resource ) ; XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder ( in , configuration , resource , configuration . getSqlFragments ( ) ) ; xmlMapperBuilder . parse ( ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { ErrorContext . instance ( ) . reset ( ) ; } sqlSessionFactory = new SqlSessionFactoryBuilder ( ) . build ( configuration ) ; }
使用DataSource初始化SqlSessionFactory
@param ds 数据源
使用DataSource初始化SqlSessionFactory