当我的应用程序关闭数据丢失时,我想在启动时使用H2。我想在应用程序关闭后保存数据库。
我的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