0

In Bean Validation 1.1, how do I change from the default ValidationMessages.properties, and use my own resource bundle?

I've seen this related issue, but it doesn't provide a solution: How to change location of ValidationMessages.properties in Bean Validation

Community
  • 1
  • 1
jersey-city-ninja
  • 1,038
  • 11
  • 23

2 Answers2

0

Simply create a file

yourProject\src\main\resources\ValidationMessages.properties

With your error messages like:

javax.validation.constraints.NotNull.message=My message, value: {value}
rgrebski
  • 2,354
  • 20
  • 29
0

Found the solution. This is not defined in the BV specs, but rather implementation-specific. I'm using the reference implementation Hibernate validator. The simplest way to achieve this is using a PlatformResourceBundle:

Validator validator = Validation.byDefaultProvider()
        .configure()
        .messageInterpolator(
                new ResourceBundleMessageInterpolator(
                        new PlatformResourceBundleLocator( "MyMessages" )
                )
        )
        .buildValidatorFactory()
        .getValidator();

See using-specific-resource-bundle-locator

jersey-city-ninja
  • 1,038
  • 11
  • 23