Check Jmix Database vs environment variables

In the application.properties file I have a db connection string like main.datasource.url=jdbc:postgresql://${POSTGRES_HOST}:${POSTGRES_PORT}/my_db

So, Check Jmix Database can’t connect to db because it don’t use environment variables in any way.

2024-06-06 19:56:39,923 [2104639] WARN - #com.haulmont.jmixstudio.intellij.runconfiguration.stepbefore.BaseSyncDbBeforeRunTaskProvider - Unable to connect to database. Cause: java.net.UnknownHostException: ${POSTGRES_HOST}. Check Data Store connection parameters.
com.haulmont.jmixstudio.exceptions.SilentException: Unable to connect to database. Cause: java.net.UnknownHostException: ${POSTGRES_HOST}. Check Data Store connection parameters.
at com.haulmont.jmixstudio.backend.ed.ddl.DbManager.getConnection(DbManager.java:167)
at com.haulmont.jmixstudio.backend.ed.ddl.DbManager.dbExists(DbManager.java:246)
at com.haulmont.jmixstudio.intellij.runconfiguration.stepbefore.SyncDbBeforeRunProcess.getStoresForCreating(SyncDbBeforeRunProcess.kt:139)
at com.haulmont.jmixstudio.intellij.runconfiguration.stepbefore.SyncDbBeforeRunProcess.access$getStoresForCreating(SyncDbBeforeRunProcess.kt:31)
at com.haulmont.jmixstudio.intellij.runconfiguration.stepbefore.SyncDbBeforeRunProcess$run$2.invokeSuspend(SyncDbBeforeRunProcess.kt:43)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:209)
at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:22)
at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:191)
at com.intellij.openapi.application.impl.RwLockHolder.runIntendedWriteActionOnCurrentThread(RwLockHolder.kt:204)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:830)
at com.intellij.openapi.application.impl.ApplicationImpl$2.run(ApplicationImpl.java:419)
at com.intellij.openapi.application.impl.RwLockHolder.runWithEnabledImplicitRead(RwLockHolder.kt:138)
at com.intellij.openapi.application.impl.RwLockHolder.runWithImplicitRead(RwLockHolder.kt:129)
at com.intellij.openapi.application.impl.ApplicationImpl.runWithImplicitRead(ApplicationImpl.java:1152)
at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:81)
at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:123)
at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:43)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:792)
at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:739)
at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:733)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:761)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:699)
at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$12(IdeEventQueue.kt:593)
at com.intellij.openapi.application.impl.RwLockHolder.runWithoutImplicitRead(RwLockHolder.kt:105)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:593)
at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:77)
at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:362)
at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:361)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:843)
at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:361)
at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:356)
at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:1022)
at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:106)
at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:1022)
at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$7(IdeEventQueue.kt:356)
at com.intellij.openapi.application.impl.RwLockHolder.runIntendedWriteActionOnCurrentThread(RwLockHolder.kt:209)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:830)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:398)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

Hello,

this is working as intended - if you have a database connection string using the environment variables,
set the environment variables.
If you don’t want to use the environment variables, use a normal connection string.

If you need different connection strings with different parameters, for your local development and deployment, you can use Spring profiles - For example is you have a normal connection string for local development, defined in application.properties, but then you make a deployment1 Spring profile, which contains different parameters, cretining file named application-deployment1.properties, and start your application with that profile.

→ many ways to set it and use it

Kind regards,
Mladen

The environment variables are set in Idea Run configuration environment variables section, but it doesn’t look like they are being used exactly Check Jmix Database on the Before launch step.

${POSTGRES_HOST} - is it a correct value? Maybe try to use IP address instead hostname

What happens if you set the environment variables in OS?

Yes, value is correct. The application starting and running correctly without “Check Jmix Database” task.