Spring Boot 2.1.5 : Failed to replace {0} with Field Name on Validation Message

标签 spring spring-boot thymeleaf

我正在尝试将 spring-boot 2.1.4 升级到 2.1.5。

在 spring-boot 2.1.4 中,带有 {0} 参数的自定义验证错误消息正确替换为字段名称。
但是 spring-boot 2.1.5,验证错误消息显示 {0} 原样。

代码

  • 消息.properties
  • notblank={0} must not be blank
    
  • PersonForm

  • import javax.validation.constraints.NotBlank;
    
    class PersonForm {
    
        @NotBlank(message = "{notblank}")
        private String name;
    
        public String getName() {
            return this.name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String toString() {
            return "Person(Name: " + this.name + ")";
        }
    }
    

    这是我的示例项目。
    https://github.com/spikefin-goby/spring-boot-validation-sample

    spring-boot 2.1.4 结果

    在 spring-boot 2.1.4 中,显示「名称不能为空」
    (正确地将 {0} 替换为 Field Name )
    spring-boot 2.1.4 validation message

    BingingResult.errors[0] 是 FieldError类(class)

    spring-boot 2.1.5 结果

    但是spring-boot 2.1.5,显示「 {0} 不能为空
    spring-boot 2.1.5 validation message

    BingingResult.errors[0] 是 LocalValidatorFactoryBean类(class)

    我该怎么办?

    更新

    Spring Boot 2.1.6 已于 2019 年 6 月 19 日发布。
    这个问题是固定的!

    在 spring-boot 2.1.6 中,显示「名称不能为空」
    (正确地将 {0} 替换为 Field Name )

    最佳答案

    在我看来,你遇到了issue #23014: validation error message {0} is not working在 spring-context-5.1.7

    关于 Spring Boot 2.1.5 : Failed to replace {0} with Field Name on Validation Message,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56535401/

    相关文章:

    java - Controller 方法不是使用 IP 而是使用 localhost 调用

    java - 在 Heroku 上使用 Spring Boot 的 Postgresql 问题

    configuration - 使用Spring Boot和Thymeleaf加载静态资源

    java - Spring Security Hierarchy 角色系统

    spring - spring 的默认 Autowiring 是什么?

    Java BigDecimal 将负值变为正值

    spring - neo4j和 Elasticsearch 在同一spring boot项目中(冲突lucene版本)

    spring - Bootstrap 不适用于 spring-boot?

    java - 在 spring boot 中使用@Profile

    spring - 使用 tomcat 池和 Spring 在 postgres 中自动重新连接