本文整理汇总了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;
}
示例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;
}
}
示例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();
}
示例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;
}
示例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);
}
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
}
示例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();
}
示例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();
}
示例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 ;
}
示例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();
}