时间:2011-01-06 19:40:05

标签: java spring spring-mvc hibernate-validator

1 个答案:

答案 0 :(得分:1)

您必须在应用程序上下文中定义messageSource:

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" abstract="false"
      scope="singleton" lazy-init="default">
    <property name="basename" value="ValidationMessages"/>
</bean>

您只需使用bean来检索消息:

@Autowired
private MessageSource messageSource;

public String getMessage(String messageName) {
    return messageSource.getMessage(messageName, null, null);
}

为了在上下文中访问bean,你也必须这样做:

@Component
public class BeanValidationTool{...