本文整理匯總了Java中org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet方法的典型用法代碼示例。如果您正苦於以下問題:Java SqlSessionFactoryBean.afterPropertiesSet方法的具體用法?Java SqlSessionFactoryBean.afterPropertiesSet怎麽用?Java SqlSessionFactoryBean.afterPropertiesSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.mybatis.spring.SqlSessionFactoryBean
的用法示例。
在下文中一共展示了SqlSessionFactoryBean.afterPropertiesSet方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
}
示例2: sqlSessionFactory
import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
@Bean
public SqlSessionFactory sqlSessionFactory() {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
DataSource dataSource = dataSource();
sqlSessionFactoryBean.setDataSource(dataSource);
String databaseType = initDatabaseType(dataSource);
if (databaseType == null) {
throw new FlowableException("couldn't deduct database type");
}
try {
Properties properties = new Properties();
properties.put("prefix", env.getProperty("datasource.prefix", ""));
properties.put("blobType", "BLOB");
properties.put("boolValue", "TRUE");
properties.load(this.getClass().getClassLoader().getResourceAsStream("org/flowable/db/properties/" + databaseType + ".properties"));
sqlSessionFactoryBean.setConfigurationProperties(properties);
sqlSessionFactoryBean
.setMapperLocations(ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath:/META-INF/modeler-mybatis-mappings/*.xml"));
sqlSessionFactoryBean.afterPropertiesSet();
return sqlSessionFactoryBean.getObject();
} catch (Exception e) {
throw new FlowableException("Could not create sqlSessionFactory", e);
}
}
示例3: initSqlSessionFactories
import org.mybatis.spring.SqlSessionFactoryBean; //導入方法依賴的package包/類
private void initSqlSessionFactories(ConfigurableListableBeanFactory beanFactory) throws Exception {
Map<String, SqlSessionFactory> sqlSessionFactories = new HashMap<>(this.dataSourceLookup.getMapping().size());
ReadWriteSplittingDataSource defaultDataSource = null;
SqlSessionFactory defaultSqlSessionFactory = null;
for (ReadWriteSplittingDataSource dataSource : this.dataSourceLookup.getMapping().values()) {
SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
sessionFactoryBean.setMapperLocations(mapperLocations);
sessionFactoryBean.setDataSource(dataSource);
sessionFactoryBean.setTypeAliasesPackage(this.packageName + ".domain.entity");
// init 初始化所有sql對應的元數據、資源(sqlNode, sqlSource, mappedStatement)等
sessionFactoryBean.afterPropertiesSet();
if (defaultDataSource == null) {
//第一個
defaultDataSource = dataSource;
defaultSqlSessionFactory = sessionFactoryBean.getObject();
} else {
SqlSessionFactory newSqlSessionFactory = sessionFactoryBean.getObject();
Field conf = newSqlSessionFactory.getClass().getDeclaredField("configuration");
conf.setAccessible(true);
Configuration newConfiguration = (Configuration) conf.get(newSqlSessionFactory);
Field mappedStatementField = newConfiguration.getClass().getDeclaredField("mappedStatements");
//去掉final修飾符
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt( mappedStatementField, mappedStatementField.getModifiers() & ~Modifier.FINAL);
mappedStatementField.setAccessible(true);
//後續的元數據複用
Configuration defaultConfiguration = defaultSqlSessionFactory.getConfiguration();
Map<String, MappedStatement> reUsedMappedStatement = (Map) mappedStatementField.get(defaultConfiguration);
mappedStatementField.set(newConfiguration, reUsedMappedStatement);
}
beanFactory.registerSingleton(dataSource.getName() + "SqlSessionFactory", sessionFactoryBean);
sqlSessionFactories.put(dataSource.getName(), sessionFactoryBean.getObject());
defaultSqlSessionFactory = sessionFactoryBean.getObject();
}
this.sqlSessionFactoryLookup = new SqlSessionFactoryLookup(sqlSessionFactories);
}