得到它了!:-)
我在我的计算机中添加了以下bean而不是上面提到的两个
dispatcher-servlet.xml:
<bean id="messageSource" > <property name="basename" value="/WEB-INF/validationMessages" /> </bean>
然后,在我的validationMessages.properties中,使用以下语法:
NotEmpty.location.title=My custom Message
我猜这是原因:我使用了Hibernate验证注释(不是javax注释)
对于一般情况,消息文件的语法应类似于
[ConstraintName].[ClassName].[FieldName]=[Message]
希望这可以帮助其他人;-)
要从spring控制器访问消息,只需将其添加
@Autowired private MessageSourcemessageSource;为类字段并使用
messageSource.getMessage方法即可。因为我只使用一种语言环境
messageSource.getMessage("NotEmpty.location.title", null, null )


