Files
spring-cloud-task/spring-cloud-task-samples/multiple-datasources
Glenn Renfro 2ef93291fc Updated Task to the latests snapshot of Micrometer
Updated to handle the batch changes

Removing aot execution from sample apps

Remove snapshot version and rely on bom

Signed-off-by: Glenn Renfro <grenfro@vmware.com>
2022-10-10 14:36:14 -04:00
..
2019-03-11 12:48:37 -05:00
2019-03-11 12:48:37 -05:00

= Multiple DataSources Sample Task

This is a Spring Boot application that utilizes two DataSources and explicitly configures
which one to be used for the Spring Cloud Task repository.

== Requirements:

* Java 17 or Above

== Classes:

* `MultipleDataSourcesApplication` - the Spring Boot Main Application.
* `SampleCommandLineRunner` - the `CommandLineRunner` implementation for this task.  It outputs the number of `DataSource` beans found in the context (should be 2).
* `EmbeddedDataSourceConfiguration` - Configures two `DataSource` beans using embedded databases.
* `ExternalDataSourceConfiguration` - Configures two `DataSource` beans using external databases.

* `CustomTaskConfigurer` - Uses a Spring `@Qualifier` to specify the correct `DataSource` to use.

== Build:

[source,shell]
----
mvn clean package
----

== Execute sample using 2 embedded databases (default):

[source,shell]
----
java -jar target/multiple-datasources-3.0.0.jar
----

== Native Build:

[source,shell]
----
mvn -Pnative clean package
----

== RUn sample using 2 embedded databases (default) with native app:

[source,shell]
----
./target/multiple-datasources
----

== Execute sample using 2 external databases:

Using the `external` profile, users will be able to establish both the default `spring.datasource` data source and a `second.datasource` data source.
For example:
[source,shell,indent=2]
----
export spring_datasource_url=<your db url>
export spring_datasource_username=<your db user name>
export spring_datasource_password=<your db user password>
export spring_datasource_driverClassName=org.mariadb.jdbc.Driver
export second_datasource_url=jdbc:<your db url>
export second_datasource_username=<your db user name>
export second_datasource_password=<your db user password>
export second_datasource_driverClassName=org.mariadb.jdbc.Driver
java -jar target/multiple-datasources-2.3.0-RELEASE.jar --spring.profiles.active=external
----