Recommend using defaultCandidate=false on qualified beans
Closes gh-42831
This commit is contained in:
@@ -12,7 +12,7 @@ This section addresses those questions.
|
||||
By default, batch applications require a `DataSource` to store job details.
|
||||
Spring Batch expects a single `DataSource` by default.
|
||||
To have it use a `DataSource` other than the application’s main `DataSource`, declare a `DataSource` bean, annotating its `@Bean` method with `@BatchDataSource`.
|
||||
If you do so and want two data sources, remember to mark the other one `@Primary`.
|
||||
If you do so and want two data sources (for example by retaining the main auto-configured `DataSource`), set the `defaultCandidate` attribute of the `@Bean` annotation to `false`.
|
||||
To take greater control, add `@EnableBatchProcessing` to one of your `@Configuration` classes or extend `DefaultBatchConfiguration`.
|
||||
See the API documentation of javadoc:{url-spring-batch-javadoc}/org.springframework.batch.core.configuration.annotation.EnableBatchProcessing[format=annotation]
|
||||
and javadoc:{url-spring-batch-javadoc}/org.springframework.batch.core.configuration.support.DefaultBatchConfiguration[] for more details.
|
||||
@@ -24,16 +24,16 @@ For more info about Spring Batch, see the {url-spring-batch-site}[Spring Batch p
|
||||
[[howto.batch.specifying-a-transaction-manager]]
|
||||
== Specifying a Batch Transaction Manager
|
||||
|
||||
Similar to xref:batch.adoc#howto.batch.specifying-a-data-source[], you can define a `PlatformTransactionManager` for use in the batch processing by marking it as `@BatchTransactionManager`.
|
||||
If you do so and want two transaction managers, remember to mark the other one as `@Primary`.
|
||||
Similar to xref:batch.adoc#howto.batch.specifying-a-data-source[], you can define a `PlatformTransactionManager` for use in batch processing by annotating its `@Bean` method with `@BatchTransactionManager`.
|
||||
If you do so and want two transaction managers (for example by retaining the auto-configured `PlatformTransactionManager`), set the `defaultCandidate` attribute of the `@Bean` annotation to `false`.
|
||||
|
||||
|
||||
|
||||
[[howto.batch.specifying-a-task-executor]]
|
||||
== Specifying a Batch Task Executor
|
||||
|
||||
Similar to xref:batch.adoc#howto.batch.specifying-a-data-source[], you can define a `TaskExecutor` for use in the batch processing by marking it as `@BatchTaskExecutor`.
|
||||
If you do so and want two task executors, remember to mark the other one as `@Primary`.
|
||||
Similar to xref:batch.adoc#howto.batch.specifying-a-data-source[], you can define a `TaskExecutor` for use in batch processing by annotating its `@Bean` method with `@BatchTaskExecutor`.
|
||||
If you do so and want two task executors (for example by retaining the auto-configured `TaskExecutor`), set the `defaultCandidate` attribute of the `@Bean` annotation to `false`.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ Beans that implement the deprecated `FlywayCallback` interface can also be detec
|
||||
|
||||
By default, Flyway autowires the (`@Primary`) `DataSource` in your context and uses that for migrations.
|
||||
If you like to use a different `DataSource`, you can create one and mark its `@Bean` as `@FlywayDataSource`.
|
||||
If you do so and want two data sources, remember to create another one and mark it as `@Primary`.
|
||||
If you do so and want two data sources (for example by retaining the main auto-configured `DataSource`), remember to set the `defaultCandidate` attribute of the `@Bean` annotation to `false`.
|
||||
Alternatively, you can use Flyway's native `DataSource` by setting `spring.flyway.[url,user,password]` in external properties.
|
||||
Setting either `spring.flyway.url` or `spring.flyway.user` is sufficient to cause Flyway to use its own `DataSource`.
|
||||
If any of the three properties has not been set, the value of its equivalent `spring.datasource` property will be used.
|
||||
@@ -184,7 +184,7 @@ In addition to YAML, Liquibase also supports JSON, XML, and SQL change log forma
|
||||
|
||||
By default, Liquibase autowires the (`@Primary`) `DataSource` in your context and uses that for migrations.
|
||||
If you need to use a different `DataSource`, you can create one and mark its `@Bean` as `@LiquibaseDataSource`.
|
||||
If you do so and you want two data sources, remember to create another one and mark it as `@Primary`.
|
||||
If you do so and want two data sources (for example by retaining the main auto-configured `DataSource`), remember to set the `defaultCandidate` attribute of the `@Bean` annotation to `false`.
|
||||
Alternatively, you can use Liquibase's native `DataSource` by setting `spring.liquibase.[driver-class-name,url,user,password]` in external properties.
|
||||
Setting either `spring.liquibase.url` or `spring.liquibase.user` is sufficient to cause Liquibase to use its own `DataSource`.
|
||||
If any of the three properties has not been set, the value of its equivalent `spring.datasource` property will be used.
|
||||
|
||||
Reference in New Issue
Block a user