or postgres) types based on a command line argument or environment. I am using spring-boot with jpa?
do you want to switch between different dbms?
yes. based on either command line argument or application.properties file
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
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
Обсуждают сегодня