|
|
|
|
@@ -1,77 +1,77 @@
|
|
|
|
|
package cn.stock.market.infrastructure.stockdb.config;
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import javax.persistence.EntityManagerFactory;
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties;
|
|
|
|
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings;
|
|
|
|
|
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
|
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.ComponentScan;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
|
|
|
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
|
|
|
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
|
|
|
|
import org.springframework.transaction.PlatformTransactionManager;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
|
|
|
|
import com.rp.spring.jpa.GenericJpaRepositoryFactoryBean;
|
|
|
|
|
import com.rp.spring.jpa.GenericJpaRepositoryImpl;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* title: ErpDatasourceConfig.java
|
|
|
|
|
* ERP 数据源设置
|
|
|
|
|
*
|
|
|
|
|
* @author rplees
|
|
|
|
|
* @email rplees.i.ly@gmail.com
|
|
|
|
|
* @version 1.0
|
|
|
|
|
* @created Jan 5, 2018 11:44:49 AM
|
|
|
|
|
*/
|
|
|
|
|
@Configuration
|
|
|
|
|
@ComponentScan({ "cn.stock.market.infrastructure.stockdb.po", "cn.stock.market.infrastructure.stockdb.repo"})
|
|
|
|
|
@EnableJpaRepositories(
|
|
|
|
|
repositoryBaseClass = GenericJpaRepositoryImpl.class,
|
|
|
|
|
repositoryFactoryBeanClass = GenericJpaRepositoryFactoryBean.class,
|
|
|
|
|
entityManagerFactoryRef = "stockEntityManagerFactory",
|
|
|
|
|
transactionManagerRef = "stockTransactionManager",
|
|
|
|
|
basePackages = { "cn.stock.market.infrastructure.stockdb.po", "cn.stock.market.infrastructure.stockdb.repo"})
|
|
|
|
|
public class StockDatasourceConfig {
|
|
|
|
|
@Autowired HibernateProperties hibernateProperties;
|
|
|
|
|
@Bean(name = "stockDataSource")
|
|
|
|
|
@ConfigurationProperties(prefix="spring.datasource.stock")
|
|
|
|
|
public DataSource dataSource() {
|
|
|
|
|
return DruidDataSourceBuilder.create().build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean(name = "stockJpaProperties")
|
|
|
|
|
@ConfigurationProperties(prefix = "spring.jpa")
|
|
|
|
|
public JpaProperties jpaProperties() {
|
|
|
|
|
return new JpaProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean(name = "stockEntityManagerFactory")
|
|
|
|
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
|
|
|
|
|
EntityManagerFactoryBuilder builder,
|
|
|
|
|
@Qualifier("stockJpaProperties") JpaProperties jpaProperties,
|
|
|
|
|
@Qualifier("stockDataSource") DataSource dataSource) {
|
|
|
|
|
Map<String, Object> properties = hibernateProperties.determineHibernateProperties(jpaProperties.getProperties(), new HibernateSettings());
|
|
|
|
|
return builder
|
|
|
|
|
.dataSource(dataSource)
|
|
|
|
|
.properties(properties)
|
|
|
|
|
.packages("cn.stock.market.infrastructure.stockdb.po")
|
|
|
|
|
.persistenceUnit("stock")
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean(name = "stockTransactionManager")
|
|
|
|
|
public PlatformTransactionManager transactionManager(@Qualifier("stockEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
|
|
|
|
|
return new JpaTransactionManager(entityManagerFactory);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//package cn.stock.market.infrastructure.stockdb.config;
|
|
|
|
|
//
|
|
|
|
|
//import java.util.Map;
|
|
|
|
|
//
|
|
|
|
|
//import javax.persistence.EntityManagerFactory;
|
|
|
|
|
//import javax.sql.DataSource;
|
|
|
|
|
//
|
|
|
|
|
//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
//import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
|
//import org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties;
|
|
|
|
|
//import org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings;
|
|
|
|
|
//import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
|
|
|
|
//import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
|
//import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
|
|
|
|
|
//import org.springframework.context.annotation.Bean;
|
|
|
|
|
//import org.springframework.context.annotation.ComponentScan;
|
|
|
|
|
//import org.springframework.context.annotation.Configuration;
|
|
|
|
|
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
|
|
|
|
//import org.springframework.orm.jpa.JpaTransactionManager;
|
|
|
|
|
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
|
|
|
|
//import org.springframework.transaction.PlatformTransactionManager;
|
|
|
|
|
//
|
|
|
|
|
//import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
|
|
|
|
//import com.rp.spring.jpa.GenericJpaRepositoryFactoryBean;
|
|
|
|
|
//import com.rp.spring.jpa.GenericJpaRepositoryImpl;
|
|
|
|
|
//
|
|
|
|
|
///**
|
|
|
|
|
// *
|
|
|
|
|
// * title: ErpDatasourceConfig.java
|
|
|
|
|
// * ERP 数据源设置
|
|
|
|
|
// *
|
|
|
|
|
// * @author rplees
|
|
|
|
|
// * @email rplees.i.ly@gmail.com
|
|
|
|
|
// * @version 1.0
|
|
|
|
|
// * @created Jan 5, 2018 11:44:49 AM
|
|
|
|
|
// */
|
|
|
|
|
//@Configuration
|
|
|
|
|
//@ComponentScan({ "cn.stock.market.infrastructure.stockdb.po", "cn.stock.market.infrastructure.stockdb.repo"})
|
|
|
|
|
//@EnableJpaRepositories(
|
|
|
|
|
// repositoryBaseClass = GenericJpaRepositoryImpl.class,
|
|
|
|
|
// repositoryFactoryBeanClass = GenericJpaRepositoryFactoryBean.class,
|
|
|
|
|
// entityManagerFactoryRef = "stockEntityManagerFactory",
|
|
|
|
|
// transactionManagerRef = "stockTransactionManager",
|
|
|
|
|
// basePackages = { "cn.stock.market.infrastructure.stockdb.po", "cn.stock.market.infrastructure.stockdb.repo"})
|
|
|
|
|
//public class StockDatasourceConfig {
|
|
|
|
|
// @Autowired HibernateProperties hibernateProperties;
|
|
|
|
|
// @Bean(name = "stockDataSource")
|
|
|
|
|
// @ConfigurationProperties(prefix="spring.datasource.stock")
|
|
|
|
|
// public DataSource dataSource() {
|
|
|
|
|
// return DruidDataSourceBuilder.create().build();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Bean(name = "stockJpaProperties")
|
|
|
|
|
// @ConfigurationProperties(prefix = "spring.jpa")
|
|
|
|
|
// public JpaProperties jpaProperties() {
|
|
|
|
|
// return new JpaProperties();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Bean(name = "stockEntityManagerFactory")
|
|
|
|
|
// public LocalContainerEntityManagerFactoryBean entityManagerFactory(
|
|
|
|
|
// EntityManagerFactoryBuilder builder,
|
|
|
|
|
// @Qualifier("stockJpaProperties") JpaProperties jpaProperties,
|
|
|
|
|
// @Qualifier("stockDataSource") DataSource dataSource) {
|
|
|
|
|
// Map<String, Object> properties = hibernateProperties.determineHibernateProperties(jpaProperties.getProperties(), new HibernateSettings());
|
|
|
|
|
// return builder
|
|
|
|
|
// .dataSource(dataSource)
|
|
|
|
|
// .properties(properties)
|
|
|
|
|
// .packages("cn.stock.market.infrastructure.stockdb.po")
|
|
|
|
|
// .persistenceUnit("stock")
|
|
|
|
|
// .build();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Bean(name = "stockTransactionManager")
|
|
|
|
|
// public PlatformTransactionManager transactionManager(@Qualifier("stockEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
|
|
|
|
|
// return new JpaTransactionManager(entityManagerFactory);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|