【发布时间】:2019-03-31 19:30:24
【问题描述】:
我想使用 JavaFx、Spring Boot 和 Spring Data JPA 制作一个桌面应用程序,并将 H2 作为我的数据库。问题是我试图运行 Junit 将数据保存在本地目录中,但每次运行 Junit 时数据都会丢失。
我的application.properties 文件;
spring.output.ansi.enabled=ALWAYS
spring.datasource.url=jdbc:h2:mem:test;
DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;
spring.datasource.platform=h2
spring.datasource.username = sa
spring.datasource.password =
spring.datasource.driverClassName = org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.generate-ddl=true
我的测试用例;
HotelEntity hotelEntity = new HotelEntity(1, "Name", "Password", "MobileNumber", "email");
hotelDao.save(hotelEntity);
System.out.println("Hotel Dao--");
List<HotelEntity> hotelEntities = hotelDao.findAll();
System.out.println(hotelEntities.size());
它打印的列表大小是 1,但是当我像这样再次运行测试用例时
List<HotelEntity> hotelEntities = hotelDao.findAll();
System.out.println(hotelEntities.size());
打印列表大小为0
【问题讨论】:
-
我的回答有帮助吗?请告诉我,如果不是,我可以提供更多帮助
标签: spring-boot spring-data-jpa h2