Remove the unconditional exposure of the transaction manager as a bean
This commit removes the unconditional exposure of the transaction manager as a bean in the application context. The transaction manager is still taken from the BatchConfigurer and set where needed (ie on JobRepository and StepBuilderFactory) as previously done, but is not exposed anymore as a bean to prevent any clash with a user defined transaction manager. If no transaction manager is provided, a DataSourceTransactionManager will be configured by default as required by batch (without being exposed as a bean). Resolves #816
This commit is contained in:
@@ -20,6 +20,7 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
|
||||
/**
|
||||
@@ -37,4 +38,9 @@ public class DataSourceConfiguration {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSourceTransactionManager transactionManager(DataSource dataSource) {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2018-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
|
||||
/**
|
||||
* @author Mahmoud Ben Hassine
|
||||
@@ -50,4 +51,9 @@ public class DataSourceConfiguration {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSourceTransactionManager transactionManager(DataSource dataSource) {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user