0

I need to specify an optional jvm argument as in:

 @PropertySource({ "${config.file:classpath:config-file.properties}" })

But it doesn't works because of the second ":".

Can someone help me ?

Context: Spring 3.12.

  • I think you have to rethink your approach because of JVM arguments supposed to be passed before JVM start but spring properties reading means settings for started application. Why no use normal jvm arguments passing via ApplicationRunner and ApplicationArguments? – AlexGera Mar 02 '18 at 15:13
  • Thanks Alex. This is only a situation, there could be another one. But, anyway, the use or properties file is an feature of Spring applied correctly with @PropertySource, and, as a plus, we can use an optional argument, and we can use jvm arguments as input. I'm thinking that there is nothing wrong with my approach. I'm using this successfully without ":" at least for 4 years. All that I need is one optional argument that could have ":" in the text, but I can't realize how to do this. The ":" means: "optional value after :" for jvm properties resolution. – Sebastião Santos Mar 02 '18 at 19:11

1 Answers1

0

I think that, as coincidence that my dependency is from "classpath:", It can works in the following way:

@PropertySource({ "${config.file:config-file.properties}" })

Spring assumes that if an PropertySource or in general any spring resource is specified without protocol as "file:" or another one, then the resource is relative to the classpath.

So I can have an property as "-Dconfig.file=another-one.properties" or if I do not present this property my default value is "config-file.properties" relative to classpath as I wanted.

This resolves my problem for now.

I expect Spring 4 resolves the parser of ":" as written on many others posts.