hibernate - spring-boot 在测试中不使用 application.properties

标签 hibernate spring-boot flyway

我有一个使用 spring、hibernate 和 Flyway 的项目来创建数据库模式。所以我有

spring.jpa.hibernate.ddl-auto: validate

在我的 application.properties 文件中。此配置在正常运行期间有效(打包可执行 jar 文件并从终端运行它之后):

2014-10-06 10:06:17.863  INFO 7519 --- [           main] o.h.tool.hbm2ddl.SchemaValidator         : HHH000229: Running schema validator

但通过 maven 运行测试时会被忽略。

1804 [main] INFO  o.h.tool.hbm2ddl.SchemaExport - HHH000227: Running hbm2ddl schema export 
1805 [main] DEBUG org.hibernate.SQL - drop table test_entity if exists 
1806 [main] DEBUG org.hibernate.SQL - drop sequence hibernate_sequence 
1807 [main] DEBUG org.hibernate.SQL - create table test_entity (id bigint not null, name    varchar(255), primary key (id)) 
1807 [main] DEBUG org.hibernate.SQL - create sequence hibernate_sequence 
1808 [main] INFO  o.h.tool.hbm2ddl.SchemaExport - HHH000230: Schema export complete 

与官方flyway-sample的主要区别似乎在于我不使用spring-boot提供的maven-parent。

完整的项目是here

最佳答案

您的测试未使用 Spring Boot(它需要使用 @SpringApplicationConfiguration 而不是 @ContextConfiguration,或声明适当的监听器)。

关于hibernate - spring-boot 在测试中不使用 application.properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26210786/

相关文章:

java - 使用 Hibernate 和 JSP 无法保存表创建和数据

hibernate - 如何正确关闭和打开 Hibernate session ?

mysql - Spring Boot+Hibernate向mysql插入空值

java - 成功登录后 Spring Boot Security 重定向 - 未定义

执行 POST 请求时 Springboot 端点 403 OPTIONS

flyway - 如何结合 Flyway 处理不在序列中的分支的合并

java - 具有自动增量的主/详细信息关系。是否可以立即坚持它们?

java - JConsole 堆转储比内存使用量小得多

java - 通过 Flyway 只执行一个 SQL 文件

maven - Heroku DATABASE_URL 作为 Maven 的 JDBC Url