|
@@ -1,71 +0,0 @@
|
|
|
-package com.ywt.biz.common.config.db;
|
|
|
-
|
|
|
-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.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;
|
|
|
-import org.springframework.transaction.PlatformTransactionManager;
|
|
|
-import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
|
-
|
|
|
-import javax.persistence.EntityManager;
|
|
|
-import javax.sql.DataSource;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by huangguoping.
|
|
|
- */
|
|
|
-@Configuration
|
|
|
-@EnableTransactionManagement
|
|
|
-@EnableJpaRepositories(
|
|
|
- entityManagerFactoryRef = "entityManagerFactory",
|
|
|
- transactionManagerRef = "transactionManager",
|
|
|
- basePackages = {"com.ywt.domain.entity.center"}
|
|
|
-)
|
|
|
-public class Ywtcenter {
|
|
|
- @Autowired
|
|
|
- @Qualifier("ywtCenterDataSource")
|
|
|
- private DataSource ywtCenterDataSource;
|
|
|
-
|
|
|
- @Primary
|
|
|
- @Bean(name = "entityManager")
|
|
|
- public EntityManager entityManager(EntityManagerFactoryBuilder builder,@Qualifier("ywtLogJpaProperties") JpaProperties jpaProperties) {
|
|
|
- return entityManagerFactory(builder,jpaProperties).getObject().createEntityManager();
|
|
|
- }
|
|
|
-
|
|
|
- @Primary
|
|
|
- @Bean(name = "entityManagerFactory")
|
|
|
- public LocalContainerEntityManagerFactoryBean entityManagerFactory (EntityManagerFactoryBuilder builder, @Qualifier("ywtLogJpaProperties") JpaProperties jpaProperties) {
|
|
|
- return builder
|
|
|
- .dataSource(ywtCenterDataSource)
|
|
|
- .properties(jpaProperties.getProperties())
|
|
|
- .properties(new HibernateProperties()
|
|
|
- .determineHibernateProperties(
|
|
|
- jpaProperties.getProperties(), new HibernateSettings()))
|
|
|
- .packages("com.ywt.domain.entity.center") //设置实体类所在位置
|
|
|
- .persistenceUnit("ywtcenterPersistenceUnit")
|
|
|
- .build();
|
|
|
- }
|
|
|
-
|
|
|
- @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());
|
|
|
- }
|
|
|
-}
|