gistfile1.txt package cn.com.lianyitech.calculate;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;import org.springframework.boot.autoconfigure.
package cn.com.lianyitech.calculate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.Database; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; import javax.sql.DataSource; import java.util.Map; @Configuration @ConditionalOnMissingClass("calculateDataSource") @EnableJpaRepositories( entityManagerFactoryRef = "calculateEntityManagerFactory", transactionManagerRef = "calculateTransactionManager",//calculateTransactionManager basePackages = "cn.com.lianyitech.calculate.repository") @EntityScan("cn.com.lianyitech.calculate.repository") @EnableTransactionManagement public class CalculateDatasourceConfigurer { @Bean public PlatformTransactionManager calculateTransactionManager() { return new JpaTransactionManager(calculateEntityManagerFactory().getObject()); } @Autowired JpaProperties jpaProperties; @Autowired Environment environment; @Bean LocalContainerEntityManagerFactoryBean calculateEntityManagerFactory() { Mapproperties = jpaProperties.getProperties(); properties.put("hibernate.default_schema", environment.getProperty("calculate.datasource.username")); HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter(); jpaVendorAdapter.setGenerateDdl(true); jpaVendorAdapter.setDatabase(Database.ORACLE); LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean(); factoryBean.setDataSource(calculateDataSource()); factoryBean.setJpaPropertyMap(properties); factoryBean.setJpaVendorAdapter(jpaVendorAdapter); factoryBean.setPersistenceUnitName("calculate"); factoryBean.setPackagesToScan(CalculateDatasourceConfigurer.class.getPackage().getName()); return factoryBean; } @Bean @ConfigurationProperties("calculate.dataSource") public DataSource calculateDataSource() { return DataSourceBuilder.create().build(); } }