Created
November 18, 2013 15:56
-
-
Save stephen-masters/7530207 to your computer and use it in GitHub Desktop.
This file contains 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 | |
@EnableTransactionManagement | |
@EnableJpaRepositories( | |
entityManagerFactoryRef = "barEntityManagerFactory", | |
transactionManagerRef = "barTransactionManager", | |
basePackages = { "com.sctrcd.multidsdemo.integration.repositories.bar" }) | |
public class BarConfig { | |
@Autowired | |
JpaVendorAdapter jpaVendorAdapter; | |
/** | |
* Primary because if we have activated embedded databases, we do not want | |
* the application to connect to an external database. | |
*/ | |
@Bean(name = "barDataSource") | |
public DataSource dataSource() { | |
return new EmbeddedDatabaseBuilder() | |
.setName("bardb") | |
.setType(EmbeddedDatabaseType.HSQL) | |
.build(); | |
} | |
@Bean(name = "barEntityManager") | |
public EntityManager entityManager() { | |
return entityManagerFactory().createEntityManager(); | |
} | |
@Bean(name = "barEntityManagerFactory") | |
public EntityManagerFactory entityManagerFactory() { | |
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean(); | |
lef.setDataSource(dataSource()); | |
lef.setJpaVendorAdapter(jpaVendorAdapter); | |
lef.setPackagesToScan("com.sctrcd.multidsdemo.domain.bar"); | |
lef.setPersistenceUnitName("barPersistenceUnit"); | |
lef.afterPropertiesSet(); | |
return lef.getObject(); | |
} | |
@Bean(name = "barTransactionManager") | |
public PlatformTransactionManager transactionManager() { | |
return new JpaTransactionManager(entityManagerFactory()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment