Skip to content

Commit dcca858

Browse files
committed
update db properties
1 parent bd2793f commit dcca858

File tree

5 files changed

+14
-23
lines changed

5 files changed

+14
-23
lines changed

persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public class MultipleDbApplication {
99
public static void main(String[] args) {
1010
SpringApplication.run(MultipleDbApplication.class, args);
1111
}
12-
12+
1313
}
1414

persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public LocalContainerEntityManagerFactoryBean productEntityManager() {
5454

5555
return em;
5656
}
57-
57+
5858
@Bean
59-
@ConfigurationProperties(prefix="spring.product")
59+
@ConfigurationProperties(prefix="spring.second-datasource")
6060
public DataSource productDataSource() {
6161
return DataSourceBuilder.create().build();
6262
}

persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public PersistenceUserAutoConfiguration() {
4343
@Primary
4444
@Bean
4545
public LocalContainerEntityManagerFactoryBean userEntityManager() {
46-
System.out.println("loading config");
4746
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
4847
em.setDataSource(userDataSource());
4948
em.setPackagesToScan("com.baeldung.multipledb.model.user");
@@ -58,9 +57,9 @@ public LocalContainerEntityManagerFactoryBean userEntityManager() {
5857
return em;
5958
}
6059

61-
@Primary
6260
@Bean
63-
@ConfigurationProperties(prefix="spring.user")
61+
@Primary
62+
@ConfigurationProperties(prefix="spring.datasource")
6463
public DataSource userDataSource() {
6564
return DataSourceBuilder.create().build();
6665
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
# user data source
2-
spring.user.driverClassName=org.h2.Driver
3-
spring.user.jdbc-url=jdbc:h2:mem:spring_jpa_user;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS
4-
spring.user.username=sa
5-
spring.user.password=sa
6-
7-
# product data source
8-
spring.product.driverClassName=org.h2.Driver
9-
spring.product.jdbc-url=jdbc:h2:mem:spring_jpa_product;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS PRODUCTS
10-
spring.product.username=sa
11-
spring.product.password=sa
12-
13-
# hibernate.X
14-
hibernate.dialect=org.hibernate.dialect.H2Dialect
15-
hibernate.show_sql=false
161
hibernate.hbm2ddl.auto=create-drop
172
hibernate.cache.use_second_level_cache=false
18-
hibernate.cache.use_query_cache=false
3+
hibernate.cache.use_query_cache=false
4+
5+
spring.datasource.jdbcUrl=jdbc:h2:mem:spring_jpa_user;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS
6+
spring.datasource.username=sa
7+
spring.datasource.password=sa
8+
9+
spring.second-datasource.jdbcUrl=jdbc:h2:mem:spring_jpa_product;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS PRODUCTS
10+
spring.second-datasource.username=sa
11+
spring.second-datasource.password=sa

persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.springframework.beans.factory.annotation.Autowired;
1313
import org.springframework.boot.test.context.SpringBootTest;
1414
import org.springframework.dao.DataIntegrityViolationException;
15-
import org.springframework.test.annotation.DirtiesContext;
1615
import org.springframework.test.context.junit4.SpringRunner;
1716
import org.springframework.transaction.annotation.EnableTransactionManagement;
1817
import org.springframework.transaction.annotation.Transactional;

0 commit comments

Comments
 (0)