Reputation: 163
I just finished the Heroku Java tutorial and wanted to try using a local database instead of the online one. So I added postgres://test:password@localhost/sample_db
as the DATABASE_URL config var and ran the example app locally using heroku local. However I was greeted with "dataSource or dataSourceClassName or jdbcUrl is required"
when I went to localhost:5000/db
, which is the page where the database is accessed.
Any idea how to resolve this or how to connect the local app with the local database?
EDIT1: The full error is ERROR 6478 --- [nio-5000-exec-7] com.zaxxer.hikari.HikariConfig: HikariPool-1 - dataSource or dataSourceClassName or jdbcUrl is required.
I think that the HikariDataSource used in the example is the problem? I tried establishing a connection with the PostgreSQL example given here and my database works fine.
EDIT2: I tried rewriting the dataSource()
method with BasicDataSource
instead of HikariDataSource
and it works (for both local and deployed). It's most certainly a HikariCP problem, or more like I don't know how to work with HikariCP and local database. The HikariCP solution works for deployed but not for local. Would certainly like to know what's the correct way of using HikariCP with local database if any!
Upvotes: 2
Views: 5372
Reputation: 1370
I configured the Hikari on local using below configuration :
<bean id="hikariSlaveDataSource" class="com.zaxxer.hikari.HikariDataSource"
depends-on="jdbcKeyStore">
<constructor-arg>
<bean class="com.zaxxer.hikari.HikariConfig">
<constructor-arg>
<bean factory-bean="jdbcKeyStore" factory-method="getDbProperties">
<constructor-arg value="jdbc.slave" />
</bean>
</constructor-arg>
<property name="dataSourceClassName"
value="com.mysql.cj.jdbc.MysqlDataSource" />
<property name="idleTimeout">
<bean factory-bean="jdbcKeyStore" factory-method="getSlaveIdleTimeout">
</bean>
</property>
<property name="maximumPoolSize">
<bean factory-bean="jdbcKeyStore" factory-method="getSlaveMaximumPoolSize">
</bean>
</property>
<property name="connectionTimeout">
<bean factory-bean="jdbcKeyStore" factory-method="getSlaveConnectionTimeout">
</bean>
</property>
<property name="maxLifetime" value="25200000" />
<property name="leakDetectionThreshold" value="60000" />
</bean>
</constructor-arg>
</bean>
Then create an entity Manager using this datasource and txnManager using defined entity manager
Upvotes: 0
Reputation: 10318
I'm not sure which example you're following, but sometimes you need to set the $JDBC_DATABASE_URL
to a value like jdbc:postgresql://localhost:5432/appdb
.
In general, the error is saying that Hikari (the database connection pool) does not have a jdbcUrl
set. It could also mean that the server is not seeing your DATABASE_URL
. Try putting it in your .env
file and run the app with heroku local web
.
Upvotes: 1