Because the XML file in spring is configured with the
<bean id= "Validator" class= "Org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" >
<property name= "Providerclass" value= "Org.hibernate.validator.HibernateValidator"/>
<!--not set by default is Validationmessages.properties---classpath
<property name= "Validationmessagesource" ref= "Validatemessagesource"/>
</bean>
In this case, the result of the read failure occurs when the properties file is read by the normal program.
For example:
Properties prop =new Properties (); InputStream in = Object.Class.getresourceasstream ("/validatemessage.properties"); try { prop.load (in); Param2 = Prop.getproperty ("InitYears2"). Trim (); }catch (IOException e) {
Todo
}
Therefore, the properties file needs to be loaded using the Org.springframework.core.io.support.PropertiesLoaderUtil class provided by spring
For example:
Resource Resource = new Classpathresource ("/validatemessages.properties");
Properties Properties = new properties (); try {
Properties = propertiesloaderutils.loadproperties (Resource);
} catch (IOException e) {
Todo
}
This will enable you to successfully read the properties file and get the desired value.
Read Properties file under Spring