I am trying to model it off of this example https://github.com/spring-projects/spring-data-examples/tree/master/jpa/multiple-datasources but they dont seem to be using a properties file, which is confusing me. How do they input the database name, log in info, and url? The way I currently have it is like this:
This is my config file for one of my databases: LM_Config.java
@Configuration
@EnableJpaRepositories(entityManagerFactoryRef = "lmEntityManagerFactory",
transactionManagerRef = "lmTransactionManager")
class LM_Config {
@Bean
PlatformTransactionManager lmTransactionManager() {
return new JpaTransactionManager(lmEntityManagerFactory().getObject());
}
@Bean
LocalContainerEntityManagerFactoryBean lmEntityManagerFactory() {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(true);
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setDataSource(lmDataSource());
factoryBean.setJpaVendorAdapter(vendorAdapter);
factoryBean.setPackagesToScan(LM_Config.class.getPackage().getName());
return factoryBean;
}
@Bean
@Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSource lmDataSource() {
return DataSourceBuilder.create().build();
}
}
This is my config file for one of my databases: MTS_Config.java
@Configuration
@EnableJpaRepositories(entityManagerFactoryRef = "mtsEntityManagerFactory",
transactionManagerRef = "mtsTransactionManager")
class MTS_Config {
@Bean
PlatformTransactionManager mtsTransactionManager() {
return new JpaTransactionManager(mtsEntityManagerFactory().getObject());
}
@Bean
LocalContainerEntityManagerFactoryBean mtsEntityManagerFactory() {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(true);
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setDataSource(mtsDataSource());
factoryBean.setJpaVendorAdapter(vendorAdapter);
factoryBean.setPackagesToScan(MTS_Config.class.getPackage().getName());
return factoryBean;
}
@Bean
@Primary
@ConfigurationProperties(prefix="spring.mtsDatasource")
public DataSource mtsDataSource() {
return DataSourceBuilder.create().build();
}
}
This is my application.properties file. The main points of interest should be the ones starting in spring.datasource...
and spring.mtsDatasource...
hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.default_schema=dbo
hibernate.packagesToScan=src.repositories.LMClientRepository.java
spring.jpa.generate-ddl=true
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.DefaultNamingStrategy
spring.datasource.username=LOADdev
spring.datasource.password=lmtdev01
spring.datasource.url=jdbc:sqlserver://schqvsqlaod:1433;database=dbMOBClientTemp;integratedSecurity=false;
spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
spring.jpa.database=dbMOBClientTemp
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
#spring.jpa.hibernate.ddl-auto=none
#spring.jpa.hibernate.ddl-auto=none
#spring.jpa.properties.hibernate.hbm2ddl.auto=none
spring.mtsDatasource.username=mtsj
spring.mtsDatasource.password=mtsjapps
spring.mtsDatasource.url=jdbc:sqlserver://SCHQVSQLCON2\VSPD:1433;database=dbMTS;integratedSecurity=false;
spring.mtsDatasource.testOnBorrow=true
spring.mtsDatasource.validationQuery=SELECT 1