Have 2 hibernate.properties files

I have a Spring Boot project with Hibernate. I would like to use 2 separate hibernate.properties files: one for normal use of application, another only for test.

So, how can I do that? Or maybe it is not possible? I don't want to comment/uncomment lines in this file for tests.

Thanks for every answers and help.

#hibernate.connection.driver_class = org.postgresql.Driver
#hibernate.connection.url = jdbc:postgresql://localhost:5432/dummydb
#hibernate.connection.username = postgres
#hibernate.connection.password = postgres
#hibernate.dialect = org.hibernate.dialect.PostgreSQL91Dialect

hibernate.connection.driver_class = org.hsqldb.jdbcDriver
hibernate.connection.url = jdbc:hsqldb:mem:dummydb
hibernate.connection.username = user
hibernate.connection.password = password
hibernate.hbm2ddl.auto=create
hibernate.dialect = org.hibernate.dialect.HSQLDialect

hibernate.show_sql=true

Upvotes: 0

Views: 85

Answers (1)

Bukharov Sergey
Bukharov Sergey

Reputation: 10185

You can use Spring profiles to separet production and test envirionments.

In your case you need to create 2 property files: application.property and application-test.property. First must contains you production env, Second envirionments for tests.

Then you need to chouse test profile when unit tests are executed. Just add @ActiveProfiles(profiles = "test") to your test classes.

Upvotes: 1

Related Questions