Does Spring Boot automatically resolve message keys in javax and hibernate validation annotations

懵懂的女人 提交于 2019-12-07 11:43:42

问题


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.


回答1:


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 ^^



来源:https://stackoverflow.com/questions/39149358/does-spring-boot-automatically-resolve-message-keys-in-javax-and-hibernate-valid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!