|
@ -10,6 +10,7 @@ import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Primary;
|
|
import org.springframework.context.annotation.Primary;
|
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
|
import org.springframework.orm.jpa.JpaVendorAdapter;
|
|
import org.springframework.orm.jpa.JpaVendorAdapter;
|
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
|
@ -32,7 +33,7 @@ import java.util.Properties;
|
|
entityManagerFactoryRef = "wlyyEntityManagerFactory",
|
|
entityManagerFactoryRef = "wlyyEntityManagerFactory",
|
|
transactionManagerRef = "wlyyTransactionManager",
|
|
transactionManagerRef = "wlyyTransactionManager",
|
|
basePackages = {"com.yihu.wlyy.figure.label.dao"}) //设置Repository所在位置
|
|
basePackages = {"com.yihu.wlyy.figure.label.dao"}) //设置Repository所在位置
|
|
public class WlyyJpa {
|
|
|
|
|
|
public class FigureLabelJpa {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private HibernateProperties hibernateProperties;
|
|
private HibernateProperties hibernateProperties;
|
|
@ -41,15 +42,7 @@ public class WlyyJpa {
|
|
@Autowired
|
|
@Autowired
|
|
private DruidConfig druidConfig;
|
|
private DruidConfig druidConfig;
|
|
|
|
|
|
|
|
|
|
@Bean(name = "wlyyDataSource")
|
|
|
|
@Primary
|
|
|
|
public DataSource wlyyDataSource() throws SQLException {
|
|
|
|
DruidDataSource datasource = new DruidDataSource();
|
|
|
|
datasource.setUrl(dataSourceProperties.getWlyy().getUrl());
|
|
|
|
datasource.setUsername(dataSourceProperties.getWlyy().getUsername());
|
|
|
|
datasource.setPassword(dataSourceProperties.getWlyy().getPassword());
|
|
|
|
datasource.setDriverClassName(dataSourceProperties.getDriverClassName());
|
|
|
|
|
|
private DataSource buildDataSource(DruidDataSource datasource) throws SQLException{
|
|
//configuration
|
|
//configuration
|
|
datasource.setInitialSize(dataSourceProperties.getInitialSize());
|
|
datasource.setInitialSize(dataSourceProperties.getInitialSize());
|
|
datasource.setMinIdle(dataSourceProperties.getMinIdle());
|
|
datasource.setMinIdle(dataSourceProperties.getMinIdle());
|
|
@ -76,12 +69,31 @@ public class WlyyJpa {
|
|
return datasource;
|
|
return datasource;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Bean(name = "wlyyDataSource")
|
|
|
|
@Primary
|
|
|
|
public DataSource wlyyDataSource() throws SQLException {
|
|
|
|
DruidDataSource datasource = new DruidDataSource();
|
|
|
|
datasource.setUrl(dataSourceProperties.getWlyy().getUrl());
|
|
|
|
datasource.setUsername(dataSourceProperties.getWlyy().getUsername());
|
|
|
|
datasource.setPassword(dataSourceProperties.getWlyy().getPassword());
|
|
|
|
datasource.setDriverClassName(dataSourceProperties.getDriverClassName());
|
|
|
|
return buildDataSource(datasource);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean(name = "healtharchiveDataSource")
|
|
|
|
public DataSource healtharchiveDataSource() throws SQLException {
|
|
|
|
DruidDataSource datasource = new DruidDataSource();
|
|
|
|
datasource.setUrl(dataSourceProperties.getHealtharchive().getUrl());
|
|
|
|
datasource.setUsername(dataSourceProperties.getHealtharchive().getUsername());
|
|
|
|
datasource.setPassword(dataSourceProperties.getHealtharchive().getPassword());
|
|
|
|
datasource.setDriverClassName(dataSourceProperties.getDriverClassName());
|
|
|
|
return buildDataSource(datasource);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean(name = "wlyyEntityManagerFactory")
|
|
@Bean(name = "wlyyEntityManagerFactory")
|
|
@Primary
|
|
@Primary
|
|
public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary(
|
|
|
|
@Qualifier("wlyyDataSource") DataSource dataSource) {
|
|
|
|
|
|
|
|
|
|
public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary(@Qualifier("wlyyDataSource") DataSource dataSource) {
|
|
LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
|
|
LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
|
|
emfb.setDataSource(dataSource);
|
|
emfb.setDataSource(dataSource);
|
|
emfb.setPackagesToScan("com.yihu.figure_label.entity");
|
|
emfb.setPackagesToScan("com.yihu.figure_label.entity");
|
|
@ -89,17 +101,13 @@ public class WlyyJpa {
|
|
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
|
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
|
|
emfb.setJpaVendorAdapter(vendorAdapter);
|
|
emfb.setJpaVendorAdapter(vendorAdapter);
|
|
emfb.setJpaProperties(hibernateProperties.hibProperties());
|
|
emfb.setJpaProperties(hibernateProperties.hibProperties());
|
|
|
|
|
|
return emfb;
|
|
return emfb;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean(name = "wlyyTransactionManager")
|
|
@Bean(name = "wlyyTransactionManager")
|
|
@Primary
|
|
@Primary
|
|
JpaTransactionManager transactionManagerSecondary(
|
|
|
|
@Qualifier("wlyyEntityManagerFactory") EntityManagerFactory builder) {
|
|
|
|
|
|
JpaTransactionManager transactionManagerSecondary(@Qualifier("wlyyEntityManagerFactory") EntityManagerFactory builder) {
|
|
return new JpaTransactionManager(builder);
|
|
return new JpaTransactionManager(builder);
|
|
}
|
|
}
|
|
|
|
|
|
@ -109,4 +117,15 @@ public class WlyyJpa {
|
|
properties.put("slowSqlMillis", "1000");
|
|
properties.put("slowSqlMillis", "1000");
|
|
return properties;
|
|
return properties;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
public JdbcTemplate jdbcTemplate(@Qualifier("wlyyDataSource") DataSource dataSource) {
|
|
|
|
return new JdbcTemplate(dataSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean(name = "healtharchiveTemplate")
|
|
|
|
public JdbcTemplate secondJdbcTemplate(@Qualifier("healtharchiveDataSource") DataSource dataSource) {
|
|
|
|
return new JdbcTemplate(dataSource);
|
|
|
|
}
|
|
}
|
|
}
|