config db
config db
config;
import java.util.HashMap;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import its.com.restful.utils.Constants;
@Configuration
@EnableJpaRepositories(basePackages = {"its.com.restful.repository"},
entityManagerFactoryRef = "db1EntityManager",
transactionManagerRef = "db1TransactionManager")
public class DataSource1Config {
@Autowired
private Environment env; // Contains Properties Load by @PropertySources
@Primary
@Bean
public DataSource db1Datasource() {
return dataSource;
}
@Primary
@Bean
public LocalContainerEntityManagerFactoryBean db1EntityManager() {
LocalContainerEntityManagerFactoryBean em = new
LocalContainerEntityManagerFactoryBean();
em.setDataSource(db1Datasource());
//
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaPropertyMap(properties);
em.afterPropertiesSet();
return em;
}
@Primary
@Bean
public PlatformTransactionManager db1TransactionManager() {
===========================================
package its.com.restful.config;
import java.util.HashMap;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import its.com.restful.utils.Constants;
@Configuration
@EnableJpaRepositories(basePackages = {"its.com.restful.repository2"},
entityManagerFactoryRef = "db2EntityManager",
transactionManagerRef = "db2TransactionManager")
public class DataSource2Config {
@Autowired
private Environment env; // Contains Properties Load by @PropertySources
@Bean
public DataSource db2Datasource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("db2.datasource.driver-class-
name"));
dataSource.setUrl(env.getProperty("db2.datasource.url"));
dataSource.setUsername(env.getProperty("db2.datasource.username"));
dataSource.setPassword(env.getProperty("db2.datasource.password"));
return dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean db2EntityManager() {
LocalContainerEntityManagerFactoryBean em = new
LocalContainerEntityManagerFactoryBean();
em.setDataSource(db2Datasource());
em.setPersistenceUnitName("db2EntityManager");
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaPropertyMap(properties);
em.afterPropertiesSet();
return em;
}
@Bean
public PlatformTransactionManager db2TransactionManager() {
}
# DataSource (voicebrandname).
db1.datasource.driver-class-name=com.mysql.jdbc.Driver
db1.datasource.url=jdbc:mysql://123.31.17.59:3306/voicebrandname?
useLegacyDatetimeCode=false&characterEncoding=UTF-8
db1.datasource.username=voicebrandname
db1.datasource.password=voicebrandname@3ITS
# DataSource (vbn_mobi).
db2.datasource.driver-class-name=com.mysql.jdbc.Driver
db2.datasource.url=jdbc:mysql://123.31.17.59:3306/vbn_mobi?
useLegacyDatetimeCode=false&characterEncoding=UTF-8
db2.datasource.username=voicebrandname
db2.datasource.password=voicebrandname@3ITS