I am using spring validation to validate the Rest Controller input, I would appreciate if any one can tell me is there a possibility of throwing custom message in case of exception and the custom message should come from database rather than from a properties file.
我正在使用spring验证来验证Rest Controller输入,如果有任何人可以告诉我是否有可能在异常情况下抛出自定义消息并且自定义消息应该来自数据库而不是来自属性文件,我将不胜感激。
1 个解决方案
#1
0
You can achieve this by setting a custom validation message source on Spring's LocalValidatorFactoryBean
.
您可以通过在Spring的LocalValidatorFactoryBean上设置自定义验证消息源来实现此目的。
Your message source needs to implement the MessageSource
interface and read its messages from the database.
您的消息源需要实现MessageSource接口并从数据库中读取其消息。
Reference:
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/MessageSource.html
#1
0
You can achieve this by setting a custom validation message source on Spring's LocalValidatorFactoryBean
.
您可以通过在Spring的LocalValidatorFactoryBean上设置自定义验证消息源来实现此目的。
Your message source needs to implement the MessageSource
interface and read its messages from the database.
您的消息源需要实现MessageSource接口并从数据库中读取其消息。
Reference:
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/MessageSource.html