0

I have a property file as below

Key1~~value1
Key2~~value2

How to read this custom separator property file using Spring.

Spring @PropertySource can read the property files with keys and values separated by = or :.

Vijay Innamuri
  • 4,242
  • 7
  • 42
  • 67
  • possible solution https://stackoverflow.com/questions/2406975/how-to-escape-the-equals-sign-in-properties-files/33808156 – M-sAnNan Sep 12 '18 at 23:55
  • that thread discusses about having the separator in keys or values. Also, the solution also is about having = or : as separator. – Vijay Innamuri Sep 13 '18 at 00:10

1 Answers1

0

On the presumption that you are using a created properties file. You can use the setGlobalSeparator(String globalSeparator) method of PropertiesConfigurationLayout and change the separator to use ~~. Per the documentation, it will overwrite the existing configuration layout to set the new global separator.

Something like this:

PropertiesConfiguration propertiesConfig = new PropertiesConfiguration("test.properties");
PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(propertiesConfig);
layout.setGlobalSeparator("~~");
propertiesConfig.setLayout(layout);
Saran
  • 1,253
  • 1
  • 9
  • 10
  • Using Spring as in? You are anyways using the `@PropertySource` annotation to get the properties file using Spring. You could use do this to set the default global separator. – Saran Sep 13 '18 at 00:49