Giriş
PlatformTransactionManager arayüzünden kalıtır.
constructor - DataSource
Örnek
Eğer bean'e isim vereceksek "transactionManager" demek gerekir. Şöyle yaparız
Şöyle yaparız.
Şöyle yaparız. DataSource olarak DriverManagerDataSource kullanılabilir.
PlatformTransactionManager arayüzünden kalıtır.
constructor - DataSource
Örnek
Eğer bean'e isim vereceksek "transactionManager" demek gerekir. Şöyle yaparız
@Bean(name = "transactionManager")
public PlatformTransactionManager creatTransactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
ÖrnekŞöyle yaparız.
@Configuration
public class PersistenceJPAConfig {
@Bean
public DriverManagerDataSource createDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
//dataSource.set ... DB stuff here
return dataSource;
}
@Bean
public PlatformTransactionManager transactionManager( ){
DataSourceTransactionManager transactionManager =
new DataSourceTransactionManager(createDataSource());
return transactionManager;
}
}
ÖrnekŞöyle yaparız. DataSource olarak DriverManagerDataSource kullanılabilir.
@Configuration
@Import(DatabaseProperties.class})
public class DatabaseConfiguration {
@Bean
public DataSource dataSource(DatabaseProperties properties) {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setUrl(properties.url);
dataSource.setUsername(properties.username);
dataSource.setPassword(properties.password);
dataSource.setDriverClassName(properties.driverClassName);
return dataSource;
}
@Bean
public PlatformTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
}
Hiç yorum yok:
Yorum Gönder