當前位置: 首頁>>代碼示例>>Java>>正文


Java SqlSessionFactoryBean.getObject方法代碼示例

本文整理匯總了Java中org.mybatis.spring.SqlSessionFactoryBean.getObject方法的典型用法代碼示例。如果您正苦於以下問題:Java SqlSessionFactoryBean.getObject方法的具體用法?Java SqlSessionFactoryBean.getObject怎麽用?Java SqlSessionFactoryBean.getObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.mybatis.spring.SqlSessionFactoryBean的用法示例。


在下文中一共展示了SqlSessionFactoryBean.getObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: businessSqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
@Primary
public SqlSessionFactory businessSqlSessionFactory(@Qualifier("businessDataSource") DruidDataSource businessDataSource) throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(businessDataSource);
    //mybatis分頁
    PageHelper pageHelper = new PageHelper();
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "true");
    props.setProperty("returnPageInfo", "check");
    props.setProperty("params", "count=countSql");
    pageHelper.setProperties(props);
    //添加插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources(MAPPERXML_LOCATION));
    return sqlSessionFactoryBean.getObject();
}
 
開發者ID:DomKing,項目名稱:busi-support,代碼行數:21,代碼來源:BusinessDatabaseConfig.java

示例2: SqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean(name = "sqlSessionFactory")
    @Primary
    public SqlSessionFactory SqlSessionFactory(@Qualifier("datasource") DataSource dataSource
            , ApplicationContext applicationContext) throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();

        // accur Could not resolve type alias in running jar
        sqlSessionFactoryBean.setVfs(SpringBootVFS.class);

        sqlSessionFactoryBean.setDataSource(dataSource);
        sqlSessionFactoryBean.setMapperLocations(
                applicationContext.getResources("classpath:META-INF/mappers/*.xml")
        );
        sqlSessionFactoryBean.setConfigLocation(
                applicationContext.getResource("classpath:META-INF/mybatis-config.xml")
        );
//        sqlSessionFactoryBean.setConfigurationProperties(mybatisProperties());
        sqlSessionFactoryBean.setTypeAliasesPackage("com.pineone.icbms.so.interfaces.database.model");

        return sqlSessionFactoryBean.getObject();
    }
 
開發者ID:iotoasis,項目名稱:SO,代碼行數:22,代碼來源:DatabaseConfig.java

示例3: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource());
    //mybatis分頁
    PageHelper pageHelper = new PageHelper();
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "true");
    props.setProperty("returnPageInfo", "check");
    props.setProperty("params", "count=countSql");
    pageHelper.setProperties(props); //添加插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:org/xxpay/dal/dao/mapper/*.xml"));
    return sqlSessionFactoryBean.getObject();
}
 
開發者ID:jmdhappy,項目名稱:xxpay-master,代碼行數:19,代碼來源:DruidDataSourceConfig.java

示例4: createSqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
public SqlSessionFactory createSqlSessionFactory() throws Exception {
    SqlSessionFactoryBean fb = new SqlSessionFactoryBean();
    fb.setDataSource(roundRobinDataSouceProxy());
    fb.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
    fb.setTypeAliasesPackage(typeAliasesPackage);
    return fb.getObject();
}
 
開發者ID:finefuture,項目名稱:data-migration,代碼行數:9,代碼來源:SqlSessionConfiguration.java

示例5: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean("sqlSessionFactory")
public SqlSessionFactory sqlSessionFactory() throws Exception {
	SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
	sessionFactory.setDataSource(dataSource());
	sessionFactory.setConfiguration(configuration());
	sessionFactory.setTypeAliasesPackage(entityBasePackage);
	sessionFactory.setTypeAliasesSuperType(AbstractEntity.class);
	sessionFactory.setMapperLocations(getResources(mapperResources));
	OffsetLimitInterceptor offserInterceptor = new OffsetLimitInterceptor();
	offserInterceptor.setDialect(new MySQLDialect());
	MapperInterceptor mapperInterceptor = new MapperInterceptor();
	Properties properties = new Properties();
	properties.setProperty("mappers", mappers);
	properties.setProperty("IDENTITY", dialect);
	mapperInterceptor.setProperties(properties);
	sessionFactory.setPlugins(new Interceptor[] { offserInterceptor ,mapperInterceptor});
	return sessionFactory.getObject();
}
 
開發者ID:swxiao,項目名稱:bubble2,代碼行數:19,代碼來源:MyBatisConfig.java

示例6: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
    public SqlSessionFactory sqlSessionFactory(DataSource dataSource,
                                               DataSourceProperties properties) throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);

        //分頁插件
//        PageHelper pageHelper = new PageHelper();
//        Properties properties = new Properties();
//        properties.setProperty("reasonable", "true");
//        properties.setProperty("supportMethodsArguments", "true");
//        properties.setProperty("returnPageInfo", "check");
//        properties.setProperty("params", "count=countSql");
//        pageHelper.setProperties(properties);
        //添加插件
//        bean.setPlugins(new Interceptor[]{pageHelper});

        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        bean.setMapperLocations(resolver.getResources(properties.getMybatisMapperLocations()));
        return bean.getObject();
    }
 
開發者ID:WinstonZheng,項目名稱:wtem,代碼行數:22,代碼來源:MybatisConfig.java

示例7: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean public SqlSessionFactory sqlSessionFactory() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource());
    //mybatis分頁
    PageHelper pageHelper = new PageHelper();
    Properties props = new Properties();
    props.setProperty("dialect", "mysql");
    props.setProperty("reasonable", "true");
    props.setProperty("supportMethodsArguments", "true");
    props.setProperty("returnPageInfo", "check");
    props.setProperty("params", "count=countSql");
    pageHelper.setProperties(props); //添加插件
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/me/caixin/dao/mapping/**/*.xml"));
    return sqlSessionFactoryBean.getObject();
}
 
開發者ID:cairenjie1985,項目名稱:springBoot-demo,代碼行數:18,代碼來源:MyBatisAutoConfiguration.java

示例8: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean(name="sqlSessionFactory")
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory() {
    try {
        SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setDataSource(dataSource);
        sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        sessionFactory.setMapperLocations(resolver.getResources(mapperLocations));
        
        PageInterceptor pageInterceptor = new MysqlPageInterceptor();
        sessionFactory.setPlugins(new Interceptor[]{pageInterceptor});
        return sessionFactory.getObject();
    } catch (Exception e) {
        logger.warn("Could not confiure mybatis session factory", e);
        return null;
    }
}
 
開發者ID:lemon-china,項目名稱:lemon-dubbo-message,代碼行數:19,代碼來源:MybatisConfiguration.java

示例9: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
  public SqlSessionFactory sqlSessionFactory(DataSource ds) throws Exception {
/*
 * 配置SqlSessionFactory的Bean
 */
      SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
      sessionFactory.setDataSource(ds);
      SqlSessionFactory factory = sessionFactory.getObject();
      
      /* 
       * 注冊Mapper。
       * 如果不注冊Mapper,則會在Spring-Boot啟動時報
       * "Type interface XXXMapper is not known to the MapperRegistry"
       */
      factory.getConfiguration().addMapper(PgDatabaseMapper.class);
      
      return factory;
  }
 
開發者ID:xiaowing,項目名稱:various_demos,代碼行數:19,代碼來源:MybatisConfig.java

示例10: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
public SqlSessionFactory sqlSessionFactory( @Autowired DynamicDataSource dynamicDataSource ) {
	try {
		SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
		sessionFactory.setDataSource(dynamicDataSource);
		sessionFactory.setTypeAliasesPackage(this.typeAliasesPackage);
		sessionFactory.setMapperLocations( new PathMatchingResourcePatternResolver().getResources(mapperLocations) );
		sessionFactory.setConfigLocation(new PathMatchingResourcePatternResolver().getResource(configLocation));
		
		PageHelper pageHelper = new PageHelper();
		Properties props = new Properties();
		props.setProperty("reasonable", "false");
		props.setProperty("supportMethodsArguments", "true");
		props.setProperty("returnPageInfo", "check");
		props.setProperty("params", "count=countSql");
		pageHelper.setProperties(props);

		sessionFactory.setPlugins(new Interceptor[] { pageHelper });

		return sessionFactory.getObject();
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
開發者ID:chxfantasy,項目名稱:micro-service-sample,代碼行數:26,代碼來源:SessionFactoryConfig.java

示例11: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
public SqlSessionFactory sqlSessionFactory() {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource());

    try {
        Properties properties = new Properties();
        properties.put("prefix", env.getProperty("datasource.prefix", ""));
        sqlSessionFactoryBean.setConfigurationProperties(properties);
        sqlSessionFactoryBean
                .setMapperLocations(ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath:/META-INF/admin-mybatis-mappings/*.xml"));
        sqlSessionFactoryBean.afterPropertiesSet();
        return sqlSessionFactoryBean.getObject();
    } catch (Exception e) {
        throw new RuntimeException("Could not create sqlSessionFactory", e);
    }

}
 
開發者ID:flowable,項目名稱:flowable-engine,代碼行數:19,代碼來源:DatabaseConfiguration.java

示例12: myBatisBatchOperationsSession

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
@Qualifier("batch-operations")
@SuppressWarnings("SpringJavaAutowiringInspection")
public SqlSession myBatisBatchOperationsSession(DataSource dataSource) throws Exception {
    /*
        NOTE: Unfortunately, in MyBatis it's not possible to execute batch and non-batch operations in single SqlSession.
        To support this scenario, we have to create completely new SqlSessionFactoryBean and completely new
        SqlSession. Surprisingly, this does not necessarily mean that the batch and non-batch operations will be
        executed in different transactions (as we would expect) - we tested this configuration using scenario 8.
        and it turned out that the bot non-batch and batch operations were run using same connection and in same transaction.
        I guess this has something to do with how connection is obtained by MyBatis from dataSource...
    */

    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);
    sqlSessionFactoryBean.setConfigLocation(new ClassPathResource("mybatis/mybatis-config.xml"));

    return new SqlSessionTemplate(sqlSessionFactoryBean.getObject(), ExecutorType.BATCH);
}
 
開發者ID:bwajtr,項目名稱:java-persistence-frameworks-comparison,代碼行數:20,代碼來源:DbTestsApplication.java

示例13: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean(name = "sqlSessionFactory")
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
	SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
	factory.setDataSource(dataSource);
	if (StringUtils.hasText(this.properties.getConfig())) {
		factory.setConfigLocation(
				this.resourceLoader.getResource(this.properties.getConfig()));
	} else {
		if (this.interceptors != null && this.interceptors.length > 0) {
			factory.setPlugins(this.interceptors);
		}
		factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
		factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
		factory.setMapperLocations(this.properties.getMapperLocations());
	}
	return factory.getObject();
}
 
開發者ID:tinyoculus,項目名稱:Dynamic-data-sources,代碼行數:19,代碼來源:MybatisAutoConfiguration.java

示例14: testAddToConfigTrue

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Test
public void testAddToConfigTrue() throws Exception {
  // the default SqlSessionFactory in AbstractMyBatisSpringTest is created with an explicitly set
  // MapperLocations list, so create a new factory here that tests auto-loading the config
  SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
  factoryBean.setDatabaseIdProvider(null);
  // mapperLocations properties defaults to null
  factoryBean.setDataSource(dataSource);
  factoryBean.setPlugins(new Interceptor[] { executorInterceptor });

  SqlSessionFactory sqlSessionFactory = factoryBean.getObject();

  find(new SqlSessionTemplate(sqlSessionFactory), true);
  assertCommit(); // SqlSesssionTemplate autocommits
  assertSingleConnection();
  assertExecuteCount(1);
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:18,代碼來源:MapperFactoryBeanTest.java

示例15: testAddToConfigFalse

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Test(expected = org.apache.ibatis.binding.BindingException.class)
public void testAddToConfigFalse() throws Throwable {
  try {
    // the default SqlSessionFactory in AbstractMyBatisSpringTest is created with an explicitly
    // set MapperLocations list, so create a new factory here that tests auto-loading the
    // config
    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    // mapperLocations properties defaults to null
    factoryBean.setDataSource(dataSource);

    SqlSessionFactory sqlSessionFactory = factoryBean.getObject();

    find(new SqlSessionTemplate(sqlSessionFactory), false);
    fail("TestDao's mapper xml should not be loaded");
  } catch (MyBatisSystemException mbse) {
    // unwrap exception so the exact MyBatis exception can be tested
    throw mbse.getCause();
  } finally {
    // connection not used; force close to avoid failing in validateConnectionClosed()
    connection.close();
  }
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:23,代碼來源:MapperFactoryBeanTest.java


注:本文中的org.mybatis.spring.SqlSessionFactoryBean.getObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。