Created
January 29, 2015 19:08
-
-
Save eddumelendez/976c30a5bc64ffcd5d74 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
datasource.mysql.url=jdbc:mysql://localhost:3306/mysql_demo | |
datasource.mysql.username=root | |
datasource.mysql.password=root | |
datasource.postgres.url=jdbc:postgresql://localhost:5432/postgres_demo | |
datasource.postgres.username=postgres | |
datasource.postgres.password=postgres |
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 | |
@EnableJpaRepositories(basePackages = "io.eddumelendez.springdatajpa.repository1") | |
public class FirstConfiguration { | |
@ConfigurationProperties(prefix = "datasource.postgres") | |
@Bean | |
@Primary | |
public DataSource postgresDataSource() { | |
return DataSourceBuilder.create(). | |
build(); | |
} | |
@Bean(name = "entityManagerFactory") | |
@Primary | |
public LocalContainerEntityManagerFactoryBean emf1(EntityManagerFactoryBuilder builder){ | |
return builder | |
.dataSource(postgresDataSource()) | |
.packages("io.eddumelendez.springdatajpa.domain1") | |
.persistenceUnit("users") | |
.build(); | |
} | |
} |
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 | |
@EnableJpaRepositories(basePackages = "io.eddumelendez.springdatajpa.repository2", entityManagerFactoryRef = "emf2") | |
public class SecondConfiguration { | |
@Bean | |
@ConfigurationProperties(prefix = "datasource.mysql") | |
public DataSource mysqlDataSource() { | |
return DataSourceBuilder.create().build(); | |
} | |
@Bean | |
public LocalContainerEntityManagerFactoryBean emf2(EntityManagerFactoryBuilder builder){ | |
return builder | |
.dataSource(mysqlDataSource()) | |
.packages("io.eddumelendez.springdatajpa.domain2") | |
.persistenceUnit("customers") | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment