答案 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{...