update db properties

This commit is contained in:
Loredana 2019-05-20 23:00:30 +03:00
parent bd2793f09e
commit dcca85823e
5 changed files with 14 additions and 23 deletions

View File

@ -9,6 +9,6 @@ public class MultipleDbApplication {
public static void main(String[] args) {
SpringApplication.run(MultipleDbApplication.class, args);
}
}

View File

@ -54,9 +54,9 @@ public class PersistenceProductAutoConfiguration {
return em;
}
@Bean
@ConfigurationProperties(prefix="spring.product")
@ConfigurationProperties(prefix="spring.second-datasource")
public DataSource productDataSource() {
return DataSourceBuilder.create().build();
}

View File

@ -43,7 +43,6 @@ public class PersistenceUserAutoConfiguration {
@Primary
@Bean
public LocalContainerEntityManagerFactoryBean userEntityManager() {
System.out.println("loading config");
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(userDataSource());
em.setPackagesToScan("com.baeldung.multipledb.model.user");
@ -58,9 +57,9 @@ public class PersistenceUserAutoConfiguration {
return em;
}
@Primary
@Bean
@ConfigurationProperties(prefix="spring.user")
@Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSource userDataSource() {
return DataSourceBuilder.create().build();
}

View File

@ -1,18 +1,11 @@
# user data source
spring.user.driverClassName=org.h2.Driver
spring.user.jdbc-url=jdbc:h2:mem:spring_jpa_user;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS
spring.user.username=sa
spring.user.password=sa
# product data source
spring.product.driverClassName=org.h2.Driver
spring.product.jdbc-url=jdbc:h2:mem:spring_jpa_product;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS PRODUCTS
spring.product.username=sa
spring.product.password=sa
# hibernate.X
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.show_sql=false
hibernate.hbm2ddl.auto=create-drop
hibernate.cache.use_second_level_cache=false
hibernate.cache.use_query_cache=false
hibernate.cache.use_query_cache=false
spring.datasource.jdbcUrl=jdbc:h2:mem:spring_jpa_user;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS
spring.datasource.username=sa
spring.datasource.password=sa
spring.second-datasource.jdbcUrl=jdbc:h2:mem:spring_jpa_product;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS PRODUCTS
spring.second-datasource.username=sa
spring.second-datasource.password=sa

View File

@ -12,7 +12,6 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;