1

Spring (3.1): Given a property file with multi line value (of course the real value is much larger):

requestStatuses=select sysdate \
from dual

I have set up Spring as described:

<util:properties id="sql_lookup_data_repo"
     location="classpath:sql_lookup_data_repo.properties"/>

And used as described:

  @Value("#{sql_lookup_data_repo.requestStatuses}")
  public void setRequestStatuses(String requestStatuses) {
    this.requestStatuses = requestStatuses;
  }

At first sight it seems to be working BUT only the first line of property value is read.

When spring is starting up it is reading the file correctly (debugged). It seems that it is lost when evaluating SpEL expression.

Is it possible to use this spring functionality with multi line property file values and how?

Already checked:

Community
  • 1
  • 1
takacsot
  • 1,727
  • 2
  • 19
  • 30
  • I can use the multi-line property value in multiple places without any problems (the lines are, of course, concatenated). Please describe the exact failure scenario. – Gary Russell Jun 03 '13 at 17:34

2 Answers2

1

Solution:

Multi line properties needs to have a backslash at the end of each line.

But if you have space (invisible!) after the backslash (before the newline) the evaluation will stop at that point.

(I am sorry but I could not make invisible characters visible in here :), so I could not provide example )

Warning: it is more about improper use of Java properties files! you can run into this problem without using @Value feature of Spring (plain Properties.load()).

takacsot
  • 1,727
  • 2
  • 19
  • 30
  • That's hardly a problem with Spring - it's a mal-formed properties file. – Gary Russell Jun 07 '13 at 09:34
  • Continued lines must end with \ – Gary Russell Jun 07 '13 at 09:40
  • Agree. It is just difficult to find becouse it is all about invisible characters. – takacsot Jun 08 '13 at 19:08
  • RIght, but my point is that this question and your self-answer seems to point the blame at Spring when this is just the way java properties files work. Spring delegates to the JVM to load the properties. If they're not well formed, they're not well formed. Period. – Gary Russell Jun 08 '13 at 23:35
  • Partially agree: from Spring `@Value` usable point of view (the way it is used in the source code) that expression can belong to any spring bean (not necessarily Properties). But in this case of course it is really my improper use of properties file. So I refrase the answere to reflect reality better. – takacsot Jun 10 '13 at 10:04
0

This works fine for me...

lines=foo \
bar \
baz

.

@Value("#{fooprops.lines}")
public void setMultiLine(String lines) {
    System.out.println(lines);
}

.

foo bar baz
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Unbelievable: Today it is working fine. It might be just computer restart or clean compile.I do not know. Thank you very much. – takacsot Jun 04 '13 at 08:48