本文整理汇总了Java中org.mybatis.spring.SqlSessionFactoryBean.setVfs方法的典型用法代码示例。如果您正苦于以下问题:Java SqlSessionFactoryBean.setVfs方法的具体用法?Java SqlSessionFactoryBean.setVfs怎么用?Java SqlSessionFactoryBean.setVfs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mybatis.spring.SqlSessionFactoryBean
的用法示例。
在下文中一共展示了SqlSessionFactoryBean.setVfs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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();
}
示例4: sqlSessionFactory
import org.mybatis.spring.SqlSessionFactoryBean; //导入方法依赖的package包/类
@Bean
@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()));
}
Configuration configuration = this.properties.getConfiguration();
if (configuration == null && !StringUtils.hasText(this.properties.getConfigLocation())) {
configuration = new Configuration();
}
if (configuration != null && !CollectionUtils.isEmpty(this.configurationCustomizers)) {
for (ConfigurationCustomizer customizer : this.configurationCustomizers) {
customizer.customize(configuration);
}
}
factory.setConfiguration(configuration);
if (this.properties.getConfigurationProperties() != null) {
factory.setConfigurationProperties(this.properties.getConfigurationProperties());
}
if (!ObjectUtils.isEmpty(this.interceptors)) {
factory.setPlugins(this.interceptors);
}
if (this.databaseIdProvider != null) {
factory.setDatabaseIdProvider(this.databaseIdProvider);
}
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();
}
示例5: createSqlSessionFactory
import org.mybatis.spring.SqlSessionFactoryBean; //导入方法依赖的package包/类
private @Nullable
SqlSessionFactory createSqlSessionFactory(
ConfigurableListableBeanFactory configurableListableBeanFactory,
String prefixName, MybatisProperties mybatisProperties) {
DataSource dataSource = configurableListableBeanFactory
.getBean(prefixName + "Ds", DataSource.class);
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setVfs(LocSpringBootVFS.class);
Optional.ofNullable(mybatisProperties.getConfigLocation()).map(this.resourceLoader::getResource)
.ifPresent(sqlSessionFactoryBean::setConfigLocation);
org.apache.ibatis.session.Configuration configuration = mybatisProperties.getConfiguration();
if (configuration == null && !StringUtils.hasText(mybatisProperties.getConfigLocation())) {
configuration = new org.apache.ibatis.session.Configuration();
}
sqlSessionFactoryBean.setConfiguration(configuration);
Optional.ofNullable(mybatisProperties.getConfigurationProperties())
.ifPresent(sqlSessionFactoryBean::setConfigurationProperties);
Optional.ofNullable(mybatisProperties.getTypeAliasesPackage())
.ifPresent(sqlSessionFactoryBean::setTypeAliasesPackage);
Optional.ofNullable(mybatisProperties.getTypeHandlersPackage())
.ifPresent(sqlSessionFactoryBean::setTypeHandlersPackage);
if (!ObjectUtils.isEmpty(mybatisProperties.resolveMapperLocations())) {
sqlSessionFactoryBean.setMapperLocations(mybatisProperties.resolveMapperLocations());
}
try {
SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBean.getObject();
if (sqlSessionFactory == null) {
log.error("sqlSessionFactoryBean get object is null");
return null;
}
register(configurableListableBeanFactory, sqlSessionFactory, prefixName + "SessionFactory",
prefixName + "Sf");
if (!Strings.isNullOrEmpty(mybatisProperties.getBasePackage())) {
createBasePackageScanner((BeanDefinitionRegistry) configurableListableBeanFactory,
mybatisProperties.getBasePackage(), prefixName);
} else {
createClassPathMapperScanner((BeanDefinitionRegistry) configurableListableBeanFactory,
prefixName);
}
return sqlSessionFactory;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}