嗨,我正在使用Spring Boot 1.5.9版 .
当使用Spring Boot为mysql数据库初始化 schema.sql
时,它工作正常,数据库模式已成功创建 . 但是在重新启动应用程序时,这个 schema.sql
脚本再次执行,应用程序无法启动,因为表已经存在 .
我在 application.properties
中尝试了 spring.jpa.hibernate.ddl-auto=create-drop
选项,但它没有任何效果(可能因为它只适用于我没有使用的Hibernate实体)
如果数据库不在内存中,有没有办法让Spring Boot每次重启时都从_565483重新创建模式?
GitHub:https://github.com/itisha/spring-batch-demo/tree/database-input
3 回答
根据documentation,您可以通过将
spring.datasource.continue-on-error
属性设置为true
来忽略异常甚至将
spring.datasource.initialize
设置为false
将其关闭解决方法可能是,更改schema.sql中的create语句
至
使用IF NOT EXISTS语句
关闭自动模式创建以避免冲突:在application.properties中添加此行