Created
February 3, 2020 08:51
-
-
Save sophea/0d9fc1594567b40ff190f22e0e8a5e2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableTransactionManagement | |
@EnableJpaRepositories(entityManagerFactoryRef = "sqlServerEntityManagerFactory", transactionManagerRef = "sqlServerTransactionManager", basePackages = "com.sma.aml.repository") | |
public class SqlServerDatabaseConfiguration { | |
@Bean | |
@ConfigurationProperties(prefix = "sqlServer.datasource") | |
public DataSourceProperties sqlServerDataSourceProperties() { | |
return new DataSourceProperties(); | |
} | |
@Bean | |
public DataSource sqlServerDataSource(@Qualifier("sqlServerDataSourceProperties") DataSourceProperties dataSourceProperties) { | |
return dataSourceProperties.initializeDataSourceBuilder().build(); | |
} | |
@Bean | |
public EntityManagerFactory sqlServerEntityManagerFactory(@Qualifier("sqlServerDataSource") DataSource sqlServerDataSource, EntityManagerFactoryBuilder builder) { | |
return builder.dataSource(sqlServerDataSource).packages("com.sma.aml.entity").persistenceUnit("sqlserver").build(); | |
} | |
@Bean | |
public PlatformTransactionManager sqlServerTransactionManager(@Qualifier("sqlServerEntityManagerFactory") EntityManagerFactory factory) { | |
JpaTransactionManager jpa = new JpaTransactionManager(factory); | |
jpa.setNestedTransactionAllowed(true); | |
jpa.setRollbackOnCommitFailure(true); | |
return jpa; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment