Похожие чаты

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 ответов

40 просмотров

do you want to switch between different dbms?

Чуткая Перфокарта
do you want to switch between different dbms?

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

Кварцевое Песнопение
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

Игривый Леопард
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

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Мелодичный Сырник
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Фетровый Лингвист
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Настойчивый Кварк
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
Льдистая Лужица
2
30500 за редактор? )
Замшевый Алхимик
47
а через ESC-код ?
Виноградная Притча
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Звенящий Циферблат
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Туманный Ларец
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Длинный Минерал
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Тягучая Ракушка
11
Карта сайта