Database 有2个hibernate.properties文件

Database 有2个hibernate.properties文件,database,hibernate,testing,junit,spring-data-jpa,Database,Hibernate,Testing,Junit,Spring Data Jpa,我有一个带Hibernate的Spring Boot项目。我想使用两个单独的hibernate.properties文件:一个用于应用程序的正常使用,另一个仅用于测试 那么,我该怎么做呢?或者这是不可能的?我不想为测试注释/取消注释此文件中的行 谢谢你的回答和帮助 #hibernate.connection.driver_class = org.postgresql.Driver #hibernate.connection.url = jdbc:postgresql://localhost:54

我有一个带Hibernate的Spring Boot项目。我想使用两个单独的hibernate.properties文件:一个用于应用程序的正常使用,另一个仅用于测试

那么,我该怎么做呢?或者这是不可能的?我不想为测试注释/取消注释此文件中的行

谢谢你的回答和帮助

#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
您可以使用来分离生产和测试环境

在本例中,您需要创建两个属性文件:application.property和application-test.property。第一个必须包含生产环境,第二个必须包含测试环境


然后,您需要在执行单元测试时选择测试概要文件。只需将@ActiveProfilesprofiles=test添加到您的测试类中。

为什么要将hibernate属性文件用于Spring启动应用程序。您可以直接在application.properties文件中配置hibernate属性。或者,如果使用yaml,则在application.yml文件中。