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
package com.sctrcd.multidsdemo; | |
import javax.persistence.EntityManagerFactory; | |
import javax.sql.DataSource; | |
import org.springframework.beans.factory.annotation.Qualifier; | |
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; | |
import org.springframework.boot.context.properties.ConfigurationProperties; | |
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | |
import org.springframework.orm.jpa.JpaTransactionManager; | |
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | |
import org.springframework.transaction.PlatformTransactionManager; | |
import org.springframework.transaction.annotation.EnableTransactionManagement; | |
@Configuration | |
@EnableTransactionManagement | |
@EnableJpaRepositories( | |
entityManagerFactoryRef = "barEntityManagerFactory", | |
transactionManagerRef = "barTransactionManager", | |
basePackages = { "com.sctrcd.multidsdemo.bar.repo" }) | |
public class BarConfig { | |
@Bean(name = "barDataSource") | |
@ConfigurationProperties(prefix="bar.datasource") | |
public DataSource barDataSource() { | |
return DataSourceBuilder.create().build(); | |
} | |
@Bean(name = "barEntityManagerFactory") | |
public LocalContainerEntityManagerFactoryBean barEntityManagerFactory( | |
EntityManagerFactoryBuilder builder, | |
@Qualifier("barDataSource") DataSource barDataSource) { | |
return builder | |
.dataSource(barDataSource) | |
.packages("com.sctrcd.multidsdemo.bar.domain") | |
.persistenceUnit("bar") | |
.build(); | |
} | |
@Bean(name = "barTransactionManager") | |
public PlatformTransactionManager barTransactionManager( | |
@Qualifier("barEntityManagerFactory") EntityManagerFactory barEntityManagerFactory) { | |
return new JpaTransactionManager(barEntityManagerFactory); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment