Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/daggerok/spring-boot-runtime-datasource-initialization
This repository contains example how to initialize different data-sources in runtime and using them to querying SQL statements
https://github.com/daggerok/spring-boot-runtime-datasource-initialization
docker gradle kotlin maven oracle postgresql spring-boot webflux
Last synced: 14 days ago
JSON representation
This repository contains example how to initialize different data-sources in runtime and using them to querying SQL statements
- Host: GitHub
- URL: https://github.com/daggerok/spring-boot-runtime-datasource-initialization
- Owner: daggerok
- License: mit
- Created: 2018-04-05T01:42:55.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-08T21:34:13.000Z (almost 7 years ago)
- Last Synced: 2024-11-11T15:37:36.982Z (2 months ago)
- Topics: docker, gradle, kotlin, maven, oracle, postgresql, spring-boot, webflux
- Language: Shell
- Homepage:
- Size: 2.57 MB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
Awesome Lists containing this project
README
= spring-boot-runtime-datasource-initialization image:https://travis-ci.org/daggerok/spring-boot-runtime-datasource-initialization.svg?branch=master["Build Status", link="https://travis-ci.org/daggerok/spring-boot-runtime-datasource-initialization"]
//tag::content[]
== Runtime datasource initialization using spring-bootThis repository contains my trying to initialize different data-sources in runtime and use them to querying / handling SQL data.
To do so, my starting point is in-memory h2 database.
I have implemented two rest resources (GET and POST).
GET resource basically showing current (by default in-memory h2) dataSource bean containing from application context.
POST resource allows you create new DataSource bean in runtime and add it to dataSourcesHolder bean.
lastly we are executing a SQL query to verify if that dataSource is working properly.prepare databases using docker (hope you have enough RAM) and start app
----
./gradlew composeUp -Pprofile=all
bash build/libs/*.jar# ora
http :8080/ \
query="select 1 from dual" \
springJpaDatabase=ORACLE \
springDatasourceUrl="jdbc:oracle:thin:@//127.0.0.1:1521/xe" \
springDatasourceUsername=system \
springDatasourcePassword=oraclepassword \
springDatasourceClassName="oracle.jdbc.OracleDriver"{
"databaseProductVersion": "Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production",
"driverName": "Oracle JDBC driver",
"driverVersion": "11.2.0.4.0",
"holdingDataSources": "{ORACLE=HikariDataSource (HikariPool-2)}",
"result": {
"columnCount": 1
},
"url": "jdbc:oracle:thin:@//127.0.0.1:1521/xe",
"userName": "SYSTEM"
}# pg
http :8080/ \
query="select 1" \
springJpaDatabase=POSTGRESQL \
springDatasourceUrl="jdbc:postgresql://0.0.0.0:5432/postgresdatabase" \
springDatasourceUsername=postgresuser \
springDatasourcePassword=postgrespassword \
springDatasourceClassName="org.postgresql.Driver"{
"databaseProductVersion": "9.4.17",
"driverName": "PostgreSQL Native Driver",
"driverVersion": "PostgreSQL 9.4.1212.jre7",
"holdingDataSources": "{ORACLE=HikariDataSource (HikariPool-2), POSTGRESQL=HikariDataSource (HikariPool-3)}",
"result": {
"columnCount": 1
},
"url": "jdbc:postgresql://0.0.0.0:5432/postgresdatabase",
"userName": "postgresuser"
}./gradlew composeDown -Pprofile=all
# or: docker-compose -f docker-compose-all.yaml down -v; docker-compose -f docker-compose-all.yaml rm -v
----////
=== basic (default) README
.gradle
----
./gradlew
java -jar build/libs/*.jar
bash build/libs/*.jar./gradlew build composeUp
./gradlew composeDown
----.maven
----
./mvnw
java -jar target/*.jar
bash target/*.jar./mvnw; ./mvnw com.dkanejs.maven.plugins:docker-compose-maven-plugin:1.0.1:up
./mvnw com.dkanejs.maven.plugins:docker-compose-maven-plugin:1.0.1:down
----
////generated by link:https://github.com/daggerok/generator-jvm/[jvm] yeoman generator
//end::content[]