[英]Spring boot and hibernate validation failure
我在 Spring Boot 中使用 Hibernate,並且只是使用以下屬性驗證模式:
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=validate
這工作正常,如果對數據庫的驗證失敗,應用程序將無法啟動(錯誤代碼 1)。
我想做的是失敗並顯示特定的錯誤代碼,因此可以對其進行處理。 我想以某種方式捕獲 SchemaManagementException,但無法看到如何做到這一點,因為驗證似乎是在創建 bean 之前的第一件事。
如果您的架構的字段命名存在問題,請使用 hack 方法來解決您的命名架構:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.