【发布时间】:2017-09-28 23:15:01
【问题描述】:
我有一个使用 Spring Boot 开发的 Spring MVC 应用程序。顺便说一下,这个应用程序仅用于学习目的。
默认情况下,应用程序启动并使用 MySQL 数据库。对于单元和集成测试,我使用了一个内存 H2 数据库,它运行良好。
现在,对于 UAT,它需要有另一个 MySQL 数据库。因此,在这个新数据库中,我已经为应用程序正常工作插入了足够的数据,但每次应用程序在 UAT 配置文件下运行时,它都会填充我必须手动清理或从 sql 文件恢复的数据。
我必须有 2 个配置文件。首先是生产概况:
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost/dbprod
spring.datasource.username = root
spring.datasource.password = mysql
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
其次,是uat配置文件:
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost/dbuat
spring.datasource.username = root
spring.datasource.password = mysql
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
然后我的问题是如何告诉 Spring 在 UAT 配置文件下它应该丢弃所做的所有更改(插入、更新和删除)。如果这可以在 application-uat.properties 文件中完成就好了
【问题讨论】:
-
通常,您在标记为
@Rollback- docs.spring.io/spring/docs/current/javadoc-api/org/… 的测试中将内容写入数据库。这将确保没有数据提交到数据库。
标签: mysql spring spring-boot properties-file