私は、エラーメッセージを更新するときに、サーバーを再起動する必要なく反映するように、SpringのReloadableResourceBundleMessageSourceをLocalValidatorFactoryBeanに使用しようとしています。私はSpring 4.1.4、hibernate-validator 4.3.2.Finalを使用しています。org.hibernate.validator.constraintsがリロードされたメッセージを選択しない
のcontext.xml - -
<mvc:annotation-driven validator="validator" />
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>file:../conf/fileapplication</value> <!-- Messages here will override the below properties file-->
<value>/WEB-INF/application</value>
</list>
</property>
<property name="cacheSeconds" value="10"></property> <!-- Will check for refresh every 10 seconds -->
</bean>
<bean name="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="validationMessageSource">
<ref bean="messageSource"/>
</property>
</bean>
モデル -
import org.hibernate.validator.constraints.NotBlank;
public class InputForm {
@NotBlank (message = "{required.string.blank}")
String requiredString;
コントローラ -
@RequestMapping(value = "/check/string", method = RequestMethod.POST)
public String checkString(
@ModelAttribute("formModel") @Valid InputForm inputForm ,
BindingResult result, Model model, HttpServletResponse response,
HttpServletRequest request) {
if (result.hasErrors()) {
model.addAttribute("formModel", inputForm);
return "userInput";
}
// Do some backend validation with String
result.reject("string.not.valid",
"String is Invalid");
model.addAttribute("formModel", inputForm);
return "userInput";
}
application.properties(/ WEB_INF /フォルダ内) は、以下のコードの詳細です
required.string.blank=Please enter the required string.
string.not.valid=Please enter a valid string.
fileapplication.properties(/ conf/folderにあります。私はそれが実行時に反映fileapplication.propertiesで「string.not.valid」を更新し、私は更新されたメッセージを見たときに今、私が直面しています問題は、ある)
required.string.blank=You did not enter the required string. #Does not reflect when I change here
string.not.valid=You did not enter a valid string. #Reflects when I change here
ファイルの上に上書きされます。しかし、fileapplication.propertiesの "required.string.blank"を更新すると、実行時に反映されません。 アプリケーションの起動時に、両方のメッセージに対して上書き部分が正常に動作していることに注意してください。しかし、 "reloading"部分は "required.string.blank"に対して正常に動作していません。