Steve Chambers Steve Chambers - 3 months ago 36
Java Question

How to inject values from another properties file into

I need to change the

message used by hibernate-validator.

Have successfully done this using a line in, e.g:
javax.validation.constraints.NotNull.message=my validation message

However, this isn't quite what's needed. Will spare the details about why but all these messages should originate from a single file, whose purpose is not only for validation but other messages as well.

Let's say initially contains a single property
CCCI_0001=my generic message
. Is it possible to somehow substitute this property value from into a placeholder in


What you can do is bootstrap your ValidatorFactory with a custom MessageInterpolator. If you are happy to use a Hibernate Validator specific feature, you can use a ResourceBundleLocator - see It looks somewhat like this:

Validator validator = Validation.byDefaultProvider()
                new ResourceBundleMessageInterpolator(
                        new PlatformResourceBundleLocator( "MyMessages" )