Похожие чаты

Hi guys, how would you switch between datasource (eg: mysql

or postgres) types based on a command line argument or environment. I am using spring-boot with jpa?

7 ответов

11 просмотров

do you want to switch between different dbms?

YohannesTz- Автор вопроса
Alireza dHb
do you want to switch between different dbms?

yes. based on either command line argument or application.properties file

YohannesTz
yes. based on either command line argument or appl...

well for mysql and postgres everything is the same except the protocol in spring.datasource.url i guess you can just set that with different values based on your environment

Alireza gave you correct suggestion, but I guess you don't understand a full picture yet without example. So, here it is. I recommend to use env vars, it's more universal approach, and the least effort one. To deploy it with mysql: export SRPING_DATASOURCE_URL='jdbc:mysql://.......' export SPRING_DATASOURCE_USERNAME='mysql-user' export SPRING_DATASOURCE_PASSWORD='mysql-password' # .... and so on java my-app.jar Same exactly app, no rebuild: export SRPING_DATASOURCE_URL='jdbc:postgresql://.......' export SPRING_DATASOURCE_USERNAME='pg-user' export SPRING_DATASOURCE_PASSWORD='pg-password' # .... and so on java my-app.jar

If you don't like default SB mechanism to resolving env vars to spring config properties, you can make aliases like: spring.datasource.url=${DB_URL:jdbc:mysql://localhost:3306.....} spring.datasource.username=${DB_USER:default-local-dev-user} spring.datasource.password=${DB_PASSWORD:default-local-dev-passwd} And then your env var names will be shorter: export DB_URL='jdbc:mysql://.......' export DB_USERNAME='mysql-user' export DB_PASSWORD='mysql-password' # .... and so on java my-app.jar

That's the documentation for default SB env vars binding mechanism https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding.environment-variables And in general, it's worth to get familiar with SB config mechanism https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config

YohannesTz- Автор вопроса
Dmytro Buryak
If you don't like default SB mechanism to resolvin...

actually I ended up doing the same thing. I am passing the dialect, platform and db credentials from an environment. and worked like a charm. thank you so much

Похожие вопросы

Обсуждают сегодня

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
any reference of this implementation?
BitBuddha
29
Ⓐrtto, [4/23/24 7:02 PM] Please explain more fully how it is not working exactly, and what are the steps you are taking, and what error messages come or what happens. Ⓐrtto, ...
Ezza Kezza
2
sounds like people have lost their kaspa on tradeogre... does this mean tradeogre not trustworthy?
Ezza Kezza
15
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
So much speculation in the last week. So much volatility in price. This is because Hedera has a GC that isn't using the network it's governing. Why aren't people asking why a...
Summit Seeker R
9
Карта сайта