Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save harish71/7826f00a499004ba2a29dcdebd1e0b3f to your computer and use it in GitHub Desktop.
Save harish71/7826f00a499004ba2a29dcdebd1e0b3f to your computer and use it in GitHub Desktop.
@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