Last active
January 5, 2016 15:59
Star
You must be signed in to star a gist
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.context.annotation.Primary; | |
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 = "entityManagerFactory", | |
basePackages = { "com.sctrcd.multidsdemo.foo.repo" }) | |
public class FooConfig { | |
@Primary | |
@Bean(name = "dataSource") | |
@ConfigurationProperties(prefix="spring.datasource") | |
public DataSource dataSource() { | |
return DataSourceBuilder.create().build(); | |
} | |
@Primary | |
@Bean(name = "entityManagerFactory") | |
public LocalContainerEntityManagerFactoryBean entityManagerFactory( | |
EntityManagerFactoryBuilder builder, | |
@Qualifier("dataSource") DataSource dataSource) { | |
return builder | |
.dataSource(dataSource) | |
.packages("com.sctrcd.multidsdemo.foo.domain") | |
.persistenceUnit("foo") | |
.build(); | |
} | |
@Primary | |
@Bean(name = "transactionManager") | |
public PlatformTransactionManager transactionManager( | |
@Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) { | |
return new JpaTransactionManager(entityManagerFactory); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment