|
@@ -1,5 +1,6 @@
|
|
package com.ywt.glasses.config.jpa;
|
|
package com.ywt.glasses.config.jpa;
|
|
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties;
|
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties;
|
|
@@ -29,10 +30,11 @@ import java.util.Map;
|
|
transactionManagerRef = "transactionManagerGlasses",
|
|
transactionManagerRef = "transactionManagerGlasses",
|
|
basePackages = {"com.ywt.glasses.domain.entity.glasses"}
|
|
basePackages = {"com.ywt.glasses.domain.entity.glasses"}
|
|
)
|
|
)
|
|
|
|
+@Slf4j
|
|
public class GlassesConfig {
|
|
public class GlassesConfig {
|
|
@Autowired
|
|
@Autowired
|
|
- @Qualifier("ywtCenterDataSource")
|
|
|
|
- private DataSource ywtCenterDataSource;
|
|
|
|
|
|
+ @Qualifier("glassesDataSource")
|
|
|
|
+ private DataSource glassesDataSource;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private JpaProperties jpaProperties;
|
|
private JpaProperties jpaProperties;
|
|
@@ -48,7 +50,7 @@ public class GlassesConfig {
|
|
EntityManagerFactoryBuilder builder) {
|
|
EntityManagerFactoryBuilder builder) {
|
|
Map<String, Object> properties = hibernateProperties.determineHibernateProperties(
|
|
Map<String, Object> properties = hibernateProperties.determineHibernateProperties(
|
|
jpaProperties.getProperties(), new HibernateSettings());
|
|
jpaProperties.getProperties(), new HibernateSettings());
|
|
- return builder.dataSource(ywtCenterDataSource).properties(properties)
|
|
|
|
|
|
+ return builder.dataSource(glassesDataSource).properties(properties)
|
|
.packages("com.ywt.glasses.domain.entity.glasses").build();
|
|
.packages("com.ywt.glasses.domain.entity.glasses").build();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -60,11 +62,12 @@ public class GlassesConfig {
|
|
@Bean(name = "entityManagerFactoryGlasses")
|
|
@Bean(name = "entityManagerFactoryGlasses")
|
|
@Primary
|
|
@Primary
|
|
public EntityManagerFactory entityManagerFactory(EntityManagerFactoryBuilder builder) {
|
|
public EntityManagerFactory entityManagerFactory(EntityManagerFactoryBuilder builder) {
|
|
|
|
+ log.info("创建 glasses 的EntityManagerFactory");
|
|
return this.entityManagerFactoryBean(builder).getObject();
|
|
return this.entityManagerFactoryBean(builder).getObject();
|
|
}
|
|
}
|
|
|
|
|
|
@Bean(name = "entityManager")
|
|
@Bean(name = "entityManager")
|
|
- //@Primary TODO 去除该标签不然会报错
|
|
|
|
|
|
+ // @Primary TODO 去除该标签不然会报错
|
|
public EntityManager entityManager(@Qualifier("entityManagerFactoryGlasses") EntityManagerFactory entityManagerFactory) {
|
|
public EntityManager entityManager(@Qualifier("entityManagerFactoryGlasses") EntityManagerFactory entityManagerFactory) {
|
|
return entityManagerFactory.createEntityManager();
|
|
return entityManagerFactory.createEntityManager();
|
|
}
|
|
}
|
|
@@ -75,6 +78,7 @@ public class GlassesConfig {
|
|
@Bean(name = "transactionManagerGlasses")
|
|
@Bean(name = "transactionManagerGlasses")
|
|
@Primary
|
|
@Primary
|
|
public PlatformTransactionManager transactionManager(EntityManagerFactoryBuilder builder) {
|
|
public PlatformTransactionManager transactionManager(EntityManagerFactoryBuilder builder) {
|
|
|
|
+ log.info("创建 glasses 的 TransactionManager");
|
|
return new JpaTransactionManager(this.entityManagerFactory(builder));
|
|
return new JpaTransactionManager(this.entityManagerFactory(builder));
|
|
}
|
|
}
|
|
}
|
|
}
|