I was writing a Spring Boot Application. I wanted to know does Spring Boot automatically resolve message keys in javax and hibernate validation annotations. For example:
@NotEmpty(message = "${message.key}")
String name;
I have provided @PropertySource
in my application with message properties file and file is also in my classpath. The keys are resolving with @Value
but they are not being resolved in validation annotations.
What could be the reason for this?
Do I need configure a message source bean? Because I have seen examples working without configuring the message source bean.
Are your messages in the correct place? Spring Boot automatically registers a MessageSource
bean for you , so you should put your messages in the src/main/resources/messages.properties
file. If you have enabled the auto-configuration and also have hibernate-validator dependency on the classpath, everything should work out of the box.
Also @PropertySource
is related to application's configuration properties and not messages so the fact that it's not resolving them is to be expected ^^
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.