java - Spring Boot 禁止属性值

标签 java spring hibernate spring-boot

有没有办法禁止在 Spring 配置中传递给定的属性值(例如 application.proeprties)。

例如,如果我们想在使用 hibernate 时防止意外的数据库架构迁移。 假设我们只想使用属性 spring.jpa.hibernate.ddl-auto 的值 validate。如果该值不是validate,则抛出异常或将其覆盖为validate

这可能吗?也许有一些“钩子(Hook)”或预处理器,可以在应用程序启动之前检查属性。

最佳答案

您可以使用EnvironmentPostProcessor来查看环境并做任何您喜欢的事情。 This section of the documentation解释了如何做到这一点。

It is also possible to customize the Environment before the application context is refreshed using EnvironmentPostProcessor. Each implementation should be registered in META-INF/spring.factories:

org.springframework.boot.env.EnvironmentPostProcessor=com.example.YourEnvironmentPostProcessor

关于java - Spring Boot 禁止属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48183891/

相关文章:

java - 服务器环境上的 Guava AbstractScheduledService

java - 复制文件时 JMeter Bean Shell Sampler 错误 "...Static method get( java.lang.String ) not found in class' java.nio.file.Paths”

java - 使用 hibernate 模板时 MySql 连接过多?

Spring <prop>标签

java - Spring Integration 一直消耗更多内存

使用 JPAKnowledgeService 创建 StatefulKnowledgeSession 时出现 java.lang.NullPointerException

java - Hibernate 序列生成的自定义

java - 将 Jsonpath 输出映射到 POJO 列表

java - 无法使用 WebFlux 在 Spring Boot 中使用 H2 和 R2DBC 创建 ConnectionFactory 错误

java - JBoss EAP 6.3 CMT 多个持久性单元