Created
March 4, 2015 09:09
-
-
Save rupert-madden-abbott/8a3af4ae04a9be71481e to your computer and use it in GitHub Desktop.
This is a workaround for: https://github.com/mybatis/spring/issues/58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class FirstDatabaseConfig implements EnvironmentAware { | |
private Environment env; | |
@Override | |
public void setEnvironment(final Environment env) { | |
this.env = env; | |
} | |
@Bean | |
public DataSource firstDataSource() { | |
BasicDataSource source = new BasicDataSource(); | |
source.setDriverClassName(env.getRequiredProperty("first.dataSource.driverClassName"); | |
//and so on | |
return source; | |
} | |
@Bean | |
public SqlSessionFactory firstSqlSessionFactory() throws Exception { | |
SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); | |
bean.setTypeAliasesPackage("org.example.model.first"); | |
bean.setDataSource(firstDataSource()); | |
return bean.getObject(); | |
} | |
@Bean | |
public MapperScannerConfigurer firstMapperScannerConfigurer() { | |
MapperScannerConfigurer configurer = new MapperScannerConfigurer(); | |
configurer.setBasePackage("org.example.mapper.first"); | |
configurer.setSqlSessionFactoryBeanName("firstSqlSessionFactory"); | |
return configurer; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class SecondDatabaseConfig implements EnvironmentAware { | |
private Environment env; | |
@Override | |
public void setEnvironment(final Environment env) { | |
this.env = env; | |
} | |
@Bean | |
public DataSource secondDataSource() { | |
BasicDataSource source = new BasicDataSource(); | |
source.setDriverClassName(env.getRequiredProperty("second.dataSource.driverClassName"); | |
//and so on | |
return source; | |
} | |
@Bean | |
public SqlSessionFactory secondSqlSessionFactory() throws Exception { | |
SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); | |
bean.setTypeAliasesPackage("org.example.model.second"); | |
bean.setDataSource(secondDataSource()); | |
return bean.getObject(); | |
} | |
@Bean | |
public MapperScannerConfigurer secondMapperScannerConfigurer() { | |
MapperScannerConfigurer configurer = new MapperScannerConfigurer(); | |
configurer.setBasePackage("org.example.mapper.second"); | |
configurer.setSqlSessionFactoryBeanName("secondSqlSessionFactory"); | |
return configurer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment