|
@@ -1,4 +1,4 @@
|
|
|
-package com.ywt.config.db;
|
|
|
+package com.ywt.jpa;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
@@ -9,7 +9,6 @@ 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.Configuration;
|
|
|
-import org.springframework.context.annotation.Primary;
|
|
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
|
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
|
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
|
@@ -18,53 +17,54 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
import javax.sql.DataSource;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
- * Created by huangguoping.
|
|
|
+ * ywt_center数据库配置
|
|
|
+ * @author dyh
|
|
|
*/
|
|
|
@Configuration
|
|
|
@EnableTransactionManagement
|
|
|
@EnableJpaRepositories(
|
|
|
- entityManagerFactoryRef = "entityManagerFactory",
|
|
|
- transactionManagerRef = "transactionManager",
|
|
|
- basePackages = {"com.ywt.domain.entity.glasses"}
|
|
|
+ entityManagerFactoryRef = "entityManagerFactoryBase",
|
|
|
+ transactionManagerRef = "transactionManagerBase",
|
|
|
+ basePackages = {"com.ywt.mg.domain.entity.center"}
|
|
|
)
|
|
|
-public class Ywtcenter {
|
|
|
+
|
|
|
+public class YwtCenterConfig {
|
|
|
@Autowired
|
|
|
- @Qualifier("glassesDataSource")
|
|
|
+ @Qualifier("ywtCenterDataSource")
|
|
|
private DataSource ywtCenterDataSource;
|
|
|
|
|
|
- @Primary
|
|
|
- @Bean(name = "entityManager")
|
|
|
- public EntityManager entityManager(EntityManagerFactoryBuilder builder,@Qualifier("ywtLogJpaProperties") JpaProperties jpaProperties) {
|
|
|
+ @Bean(name = "entityManagerBase")
|
|
|
+ public EntityManager entityManager(EntityManagerFactoryBuilder builder,@Qualifier("ywtCenterJpaProperties") JpaProperties jpaProperties) {
|
|
|
return entityManagerFactory(builder,jpaProperties).getObject().createEntityManager();
|
|
|
}
|
|
|
|
|
|
- @Primary
|
|
|
- @Bean(name = "entityManagerFactory")
|
|
|
- public LocalContainerEntityManagerFactoryBean entityManagerFactory (EntityManagerFactoryBuilder builder, @Qualifier("ywtLogJpaProperties") JpaProperties jpaProperties) {
|
|
|
+ @Bean(name = "entityManagerFactoryBase")
|
|
|
+ public LocalContainerEntityManagerFactoryBean entityManagerFactory (EntityManagerFactoryBuilder builder, @Qualifier("ywtCenterJpaProperties") JpaProperties jpaProperties) {
|
|
|
return builder
|
|
|
.dataSource(ywtCenterDataSource)
|
|
|
.properties(jpaProperties.getProperties())
|
|
|
.properties(new HibernateProperties()
|
|
|
.determineHibernateProperties(
|
|
|
jpaProperties.getProperties(), new HibernateSettings()))
|
|
|
- .packages("com.ywt.domain.entity.glasses") //设置实体类所在位置
|
|
|
- .persistenceUnit("ywtGlassesPersistenceUnit")
|
|
|
+ .packages("com.ywt.mg.domain.entity.center") //设置实体类所在位置
|
|
|
+ .persistenceUnit("askcenterPersistenceUnit")
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
- @Bean(name = "ywtGlassesJpaProperties")
|
|
|
- @ConfigurationProperties(prefix = "spring.jpa.glasses")
|
|
|
+ @Autowired
|
|
|
+ private JpaProperties jpaProperties;
|
|
|
+
|
|
|
+ @Bean(name = "ywtCenterJpaProperties")
|
|
|
+ @ConfigurationProperties(prefix = "spring.jpa.ywtcenter")
|
|
|
public JpaProperties jpaProperties() {
|
|
|
return new JpaProperties();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- @Primary
|
|
|
- @Bean(name = "transactionManager")
|
|
|
- public PlatformTransactionManager transactionManager(EntityManagerFactoryBuilder builder,@Qualifier("ywtLogJpaProperties") JpaProperties jpaProperties) {
|
|
|
- return new JpaTransactionManager(entityManagerFactory(builder,jpaProperties).getObject());
|
|
|
+ @Bean(name = "transactionManagerBase")
|
|
|
+ public PlatformTransactionManager transactionManager(EntityManagerFactoryBuilder builder) {
|
|
|
+ return new JpaTransactionManager(entityManagerFactory(builder, jpaProperties()).getObject());
|
|
|
}
|
|
|
}
|