Quartz属性文件传入环境变量

时间:2018-03-13 21:18:47

标签: java java-8 quartz-scheduler dropwizard

我正在尝试将环境变量添加到我的quartz属性文件中,但它没有正确加载。

继承我的quartz.properties

  org.quartz.scheduler.instanceName: scheduler
  org.quartz.scheduler.instanceId: AUTO
  org.quartz.scheduler.skipUpdateCheck: true
  org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
  org.quartz.threadPool.threadCount: 10
  org.quartz.threadPool.threadPriority: 5
  org.quartz.jobStore.misfireThreshold: 60000
  org.quartz.jobStore.class: org.quartz.impl.jdbcjobstore.JobStoreTX
  org.quartz.jobStore.driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
  org.quartz.jobStore.useProperties: false
  org.quartz.jobStore.dataSource: myDS
  org.quartz.jobStore.tablePrefix: QRTZ_
  org.quartz.jobStore.isClustered: true
  org.quartz.dataSource.myDS.driver: org.postgresql.Driver
  org.quartz.dataSource.myDS.URL: ${APP_JDBC_URL:-jdbc:postgresql://localhost:5432/db}
  org.quartz.dataSource.myDS.user:  ${APP_JDBC_USER:-user}
  org.quartz.dataSource.myDS.password: ${APP_JDBC_PASSWORD:-pass}
  org.quartz.dataSource.myDS.maxConnections: 5
  org.quartz.dataSource.myDS.validationQuery: select 1

例外:

ERROR [2018-03-13 21:11:13,958] org.quartz.impl.jdbcjobstore.JobStoreTX: ClusterManager: Error managing cluster: Failed to obtain DB connection from data source 'myDS': java.sql.SQLException: Connections could not be acquired from the underlying database!
! com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
! at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
! at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
! at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
! at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
! ... 26 common frames omitted

2 个答案:

答案 0 :(得分:0)

quartz.properties文件通过遵循以下约定来读取环境变量:$@environment_variable_name

例如,这适用于我的应用程序:

org.quartz.threadPool.threadCount=$@QUARTZ_THREAD_COUNT

在这种情况下,您应该可以使用:

org.quartz.dataSource.myDS.URL=$@APP_JDBC_URL
org.quartz.dataSource.myDS.user=$@APP_JDBC_USER
org.quartz.dataSource.myDS.password=$@APP_JDBC_PASSWORD

答案 1 :(得分:-3)

请不要使用连字符

org.quartz.dataSource.myDS.URL:$ {APP_JDBC_URL:JDBC:在PostgreSQL://本地主机:5432 /分贝} org.quartz.dataSource.myDS.user:$ {APP_JDBC_USER:用户} org.quartz.dataSource.myDS.password:$ {APP_JDBC_PASSWORD:通}

例如我的配置有效:adb.datasource.url = $ {DB1_URL:jdbc:sqlserver://127.0.0.1:1433; databaseName = authdb}