question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

spring boot unable to interpolate message for jsr-303 validation

See original GitHub issue

if I define the following validation messages,

@Size(min = 3, message = "{validation.account.name}")
private String name;

I expect spring boot would read from messages*.properties from classpath and find the validation.account.name key to interpolate the message, but it just shows {validation.account.name} on the page.

This https://github.com/Zane-XY/springboot-i18n-problem demos the problems.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:7
  • Comments:29 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
php-codercommented, Jun 1, 2015

IMHO it should be easy to implement, like this:

public class MvcConfig extends WebMvcConfigurerAdapter {

    @Inject
    private MessageSource messageSource;

    @Override
    public Validator getValidator() {
        LocalValidatorFactoryBean factory = new LocalValidatorFactoryBean();
        factory.setValidationMessageSource(messageSource);
        return factory;
    }
}
2reactions
selimokcommented, Jan 11, 2017

It works.

To get it worked I have to move validation keys into the file ValidationMessages.properties while all oder messages reside in messages.properties.

FYI.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Springboot error message interpolation not working for custom ...
When i run my springboot application, the interpolation works for JSR-303, but not the custom validator, did i miss something? Tried for long ......
Read more >
Spring Validation Message Interpolation | Baeldung
Message interpolation is the process used for creating error messages for Java bean validation constraints. For example, we can see the messages ......
Read more >
Java Bean Validation - Interpolating constraint error messages
The message element value represents validation error message. This element usage is optional on client side. If not specified a default message ......
Read more >
Chapter 4. Interpolating constraint error messages
Message interpolation is the process of creating error messages for violated Bean Validation constraints. In this chapter you will learn how such messages...
Read more >
5. Validation, Data Binding, and Type Conversion - Spring
Outputting messages corresponding to validation errors is the last thing we need ... JSR-303 constructs, from message interpolation to traversal resolution.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found