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


Java SqlSessionFactoryBean.setConfigLocation方法代碼示例

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


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

示例1: sqlSessionFactoryBean

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
public SqlSessionFactoryBean sqlSessionFactoryBean(
        DataSource dataSource,
        ApplicationContext applicationContext) throws IOException {

    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();

    // 마이바티스가 사용한 DataSource를 등록
    factoryBean.setDataSource(dataSource);

    // 마이바티스 설정파일 위치 설정
    factoryBean.setConfigLocation(applicationContext.getResource("classpath:mybatis-config.xml"));
    factoryBean.setMapperLocations(applicationContext.getResources("classpath:net/andromedarabbit/persistence/mybatis/**/*.xml"));

    factoryBean.setPlugins(new Interceptor[]{
            new PaginationInterceptor(),
            new PaginationResultSetHandlerInterceptor()
    });

    return factoryBean;
}
 
開發者ID:andromedarabbit,項目名稱:mybatis-pagination,代碼行數:22,代碼來源:MyBatisConfig.java

示例2: 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

示例3: 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

示例4: createSqlSessionFactoryBean

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(env.getProperty("mybatis.config-location")));
    PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
    String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + env.getProperty("mybatis.mapper-locations");
    sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(packageSearchPath));
    sqlSessionFactoryBean.setDataSource(dataSource());

    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", env.getProperty("pageHelper.reasonable"));
    properties.setProperty("supportMethodsArguments", env.getProperty("pageHelper.supportMethodsArguments"));
    properties.setProperty("returnPageInfo", env.getProperty("pageHelper.returnPageInfo"));
    properties.setProperty("params", env.getProperty("pageHelper.params"));
    pageHelper.setProperties(properties);
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});

    return sqlSessionFactoryBean;
}
 
開發者ID:myopenresources,項目名稱:cc-s,代碼行數:21,代碼來源:MyBatisConfig.java

示例5: dynamicSqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
/**
 * Dynamic sql session factory sql session factory.
 *
 * @param dynamicDataSource the dynamic data source
 * @param properties        the properties
 * @return the sql session factory
 */
@Bean
@ConfigurationProperties(prefix = MybatisProperties.MYBATIS_PREFIX)
public SqlSessionFactory dynamicSqlSessionFactory(
		@Qualifier("dynamicDataSource") DataSource dynamicDataSource,
		MybatisProperties properties) {
	final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
	sessionFactory.setDataSource(dynamicDataSource);
	sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(properties.getConfigLocation()));
	sessionFactory.setMapperLocations(properties.resolveMapperLocations());
	try {
		return sessionFactory.getObject();
	} catch (Exception e) {
		throw new SystemException(e);
	}
}
 
開發者ID:ruyangit,項目名稱:angit,代碼行數:23,代碼來源:DatasourceConfig.java

示例6: 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

示例7: 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

示例8: 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);
    factory.setVfs(SpringBootVFS.class);
    if (StringUtils.hasText(this.properties.getConfigLocation())) {
        factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
    }
    org.apache.ibatis.session.Configuration configuration = this.properties.getConfiguration();
    if (configuration == null && !StringUtils.hasText(this.properties.getConfigLocation())) {
        configuration = new org.apache.ibatis.session.Configuration();
    }
    factory.setConfiguration(configuration);
    if (this.properties.getConfigurationProperties() != null) {
        factory.setConfigurationProperties(this.properties.getConfigurationProperties());
    }
    if (!ObjectUtils.isEmpty(this.interceptors)) {
        factory.setPlugins(this.interceptors);
    }
    if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
        factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
    }
    if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
        factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
    }
    if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
        factory.setMapperLocations(this.properties.resolveMapperLocations());
    }

    return factory.getObject();
}
 
開發者ID:weiwei02,項目名稱:Yoghurt,代碼行數:33,代碼來源:MybatisAutoConfiguration.java

示例9: mafMasterSqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean(name = ConfigConstant.NAME_DS_SSF_MASTER)
@Primary
public SqlSessionFactory mafMasterSqlSessionFactory(@Qualifier(ConfigConstant.NAME_DS_MASTER) DataSource mafMasterDataSource) throws Exception {
    logger.info("----- MAFIA master data source sql session factory INIT -----");
    final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(mafMasterDataSource);
    sessionFactory.setConfigLocation(new ClassPathResource(ConfigConstant.NAME_MYBATIS_CONFIG));
    return sessionFactory.getObject();
}
 
開發者ID:slking1987,項目名稱:mafia,代碼行數:10,代碼來源:DsMasterConfig.java

示例10: mafSlaveSqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean(name = ConfigConstant.NAME_DS_SSF_SLAVE)
public SqlSessionFactory mafSlaveSqlSessionFactory(@Qualifier(ConfigConstant.NAME_DS_SLAVE) DataSource mafSlaveDataSource) throws Exception {
    logger.info("----- MAFIA slave data source sql session factory INIT -----");
    final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(mafSlaveDataSource);
    sessionFactory.setConfigLocation(new ClassPathResource(ConfigConstant.NAME_MYBATIS_CONFIG));
    return sessionFactory.getObject();
}
 
開發者ID:slking1987,項目名稱:mafia,代碼行數:9,代碼來源:DsSlaveConfig.java

示例11: sqlSessionFactoryBean

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactoryBean() {
    try {
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        bean.setConfigLocation(resolver.getResource("classpath:mybatis-config.xml"));
        bean.setMapperLocations(resolver.getResources("classpath:com/boilerplate/server/dao/*.xml"));
        bean.setTypeAliasesPackage("com.boilerplate.server.dao");
        return bean.getObject();
    } catch (Exception e) {
        throw new IllegalStateException("Init sqlSessionFactory failed!", e);
    }
}
 
開發者ID:sisyphsu,項目名稱:server-boilerplate,代碼行數:15,代碼來源:MyBatisConfig.java

示例12: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
    bean.setDataSource(dataSource);
    bean.setConfigLocation(new ClassPathResource("/mybatis-config.xml"));
    return bean.getObject();
}
 
開發者ID:projectsrepos,項目名稱:jim,代碼行數:8,代碼來源:GenericDBConfig.java

示例13: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
@Primary
public SqlSessionFactory sqlSessionFactory() throws Exception {
	SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
	sqlSessionFactoryBean.setDataSource(dataSource());
	sqlSessionFactoryBean.setConfigLocation(applicationContext.getResource("classpath:mybatis-config.xml"));
	sqlSessionFactoryBean.setMapperLocations(applicationContext.getResources("classpath:mapper/*.xml"));
	return sqlSessionFactoryBean.getObject();
}
 
開發者ID:EnterKey,項目名稱:enterkey-framework,代碼行數:10,代碼來源:DBConfig.java

示例14: sessionFactoryBean

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
public SqlSessionFactoryBean sessionFactoryBean(DataSource dataSource , Environment environment) throws IOException{
	SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean() ;
	sqlSessionFactoryBean.setDataSource(dataSource);
	//別名包
	sqlSessionFactoryBean.setTypeAliasesPackage(environment.getRequiredProperty(PROPERTY_MYBATIS_ALIAS_PACKAGE));
	
	PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver() ;
	//獲取mybatis映射文件路徑,classpath:mybatis/mybatis-config.xml
	if(environment.containsProperty(PROPERTY_MYBATIS_CONFIG)){
		sqlSessionFactoryBean.setConfigLocation(resolver.getResource(environment.getRequiredProperty(PROPERTY_MYBATIS_CONFIG)));
	}
	//獲取mybatis映射文件路徑,例:classpath*:com/framework/sample/mapper/*Mapper.xml
	sqlSessionFactoryBean.setMapperLocations(resolver.getResources(environment.getRequiredProperty(PROPERTY_MYBATIS_MAPPER_LOCATION)));

	//開啟後將在啟動時檢查設定的parameterMap,resultMap是否存在,是否合法
	sqlSessionFactoryBean.setFailFast(true) ;

	//存儲mybatis的插件
	List<Interceptor> interceptorList = new ArrayList<Interceptor>() ;
	//初始化mybatis的插件
	initPlugins(interceptorList , environment) ;
	//設置mybatis插件
	sqlSessionFactoryBean.setPlugins(interceptorList.toArray(new Interceptor[]{}));

	//創建自定義的的Configuration
	Configuration configuration = new Configuration() ;
	//設置ObjectWrapperFactory,在其中映射mybatis查詢結果和jpa實體
	configuration.setObjectWrapperFactory(new JPAObjectWrapperFactory());
	sqlSessionFactoryBean.setConfiguration(configuration);

	return sqlSessionFactoryBean ;
}
 
開發者ID:lp895876294,項目名稱:genericdao,代碼行數:34,代碼來源:MybatisConfig.java

示例15: sqlSessionFactory

import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
/**
 * 定義sqlSessionFactory的bean
 *
 * @param dataSource
 * @return
 * @throws Exception
 */
@Bean(name = "sqlSessionFactory")
@ConditionalOnMissingBean
//不允許特定的bean出現來跳過配置
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
	SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
	sqlSessionFactoryBean.setDataSource(dataSource);
	sqlSessionFactoryBean.setVfs(SpringBootVFS.class);
	if (StringUtils.hasText(this.properties.getConfigLocation())) {
		sqlSessionFactoryBean.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
	}

	sqlSessionFactoryBean.setConfiguration(properties.getConfiguration());
	if (!ObjectUtils.isEmpty(this.interceptors)) {
		sqlSessionFactoryBean.setPlugins(this.interceptors);
	}
	if (this.databaseIdProvider != null) {
		sqlSessionFactoryBean.setDatabaseIdProvider(this.databaseIdProvider);
	}
	if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
		sqlSessionFactoryBean.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
	}
	if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
		sqlSessionFactoryBean.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
	}
	if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
		sqlSessionFactoryBean.setMapperLocations(this.properties.resolveMapperLocations());
	}
	sqlSessionFactoryBean.setMybatisRefreshProperties(mybatisRefreshProperties);
	return sqlSessionFactoryBean.getObject();
}
 
開發者ID:whatlookingfor,項目名稱:spring-boot-sample,代碼行數:38,代碼來源:MybatisConfig.java


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