Reputation: 402
I have been trying a Dropwizard project using Maven. I can run hello world programs. When I tried to run database program using Hibernate, I got an error like below when running the program using java -jar.
default configuration has the following errors:
* database.driverClass may not be null (was null)
* database.url may not be null (was null)
* database.user may not be null (was null)
* template may not be empty (was null)
This is my hello-world.yml file
template: Hello, %s!
defaultName: Stranger
database:
driverClass: com.mysql.jdbc.Driver
user: root
password:
url: jdbc:mysql://localhost/test
Thanks in advance !!
Upvotes: 4
Views: 2593
Reputation: 4325
I was having the same error, but a different solution fixed it. You're supposed to pass in your yml file as an argument when you run an io.dropwizard.Application in server mode. For example
public static void main(String[] args) throws Exception {
new ApiApplication().run(new String[] {"server", "db.yaml"});
}
Adding the "db.yaml" argument to my array of strings fixed it. Or if you're passing your args from the termina/console, you'd want to add "yourconfig.yaml" or "yourconfig.yml" as the 2nd argument.
Source of the solution I found
Upvotes: 3
Reputation: 16354
As stated in some examples throught the Dropwizard repository, you may need to provide your template file configuration so that database properties are pulled out from there.
So have you tried running you application to set up your database with the .yml file as a command line argument? Something like the following:
java -jar your-artifact.jar db migrate your-configuration-file.yml
Then run your application as follows:
java -jar your-artifact.jar server your-configuration-file.yml
Upvotes: 5