JSR 303: Bean Validation. Custom message from file

2013-08-24 14:30:39


    @NotNull(message = "{postDto.id.notNull}")
    private Long id;

    @NotEmpty(message = "{postDto.name.notEmpty}")
    private String name;

    @NotNull(message = "{postDto.desc.notNull}")
    @Size(min = 5, max=10, message = "{postDto.desc.size}")
    private String description;


postDto.id.notNull=Id should be pass
postDto.name.notEmpty=Name should be pass
postDto.description.size=Description size must be between {min} and {max}
postDto.description.notNull=Description should be pass

If you want switch language, for example in test you can use:

    public void before() {
        Locale.setDefault(new Locale("en_us"));