View Full Version : property-placeholder and validation
Jun 1st, 2012, 01:35 AM
I use the <context:property-placeholder location=".........." /> XML element to retrieve properties from a file. I would like to know if there is a mechanism provided by Spring to validate the values retrieved from the file?
If no, what is the best practice to implement this requirement?
Jun 1st, 2012, 03:53 AM
No there isn't.. And also the property-placeholder isn't to be used to retrieve properties and use them later on as a properties object. For that there is the properties element in the util namespace. But that has no validation logic either.
What is it you want to validate?!
Jun 1st, 2012, 06:51 AM
Thanks for your answer Marten, I always used property-placeholder to retrieve properties from a file until now and it always worked. It's also what I've always seen on the web. I've never heard about the <util:properties> element. What is the difference between them?
I want to validate the properties retrieved from the file. For example, checking that a property that should be an integer is really an integer. Basic validation rules...
Jun 1st, 2012, 06:57 AM
The property-placeholder is used to read a properties file and then replace the placeholders in the context it is not to be used to read properties and then use the properties object (which is hard to access) as is.
The logic you want is pretty custom so I guess you would have to write something yourself (probably extending the PropertiesFactoryBean and add the logic in there). Spring will blow up when you try to replace a property which should be an integer and which is a string for instance.
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.