-1

Application.yaml:

request.delay.ms: 200

A spring component:

@Value("${request.delay.ms}")
private long requestDelay;

Now, as strange as it sounds, it looks like spring can successfully resolve the property if it's value is a string, i.e. if I change 200 to 200a. It does throw an error Caused by: java.lang.NumberFormatException: For input string: "200a" but that's expected.

If I change the value back to 200 I get Caused by: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'long'; nested exception is java.lang.NumberFormatException: For input string: "${request.delay.ms}"

And if I run tomcat in debug mode and step through the spring code, it works fine with no errors.

String @Value(s) are resolved fine in the same component all the time.

Leo
  • 1,016
  • 1
  • 13
  • 32

1 Answers1

0

If you are using YAML instead of .properties you should write it in the following manner:

request:
  delay:
    ms: 200

which will be transformed to properties:

request.delay.ms=200 but you are mixing both files

See more here

Nikolay Rusev
  • 4,060
  • 3
  • 19
  • 29
  • How does this explain the case op `200a`? – Sotirios Delimanolis Oct 29 '15 at 14:44
  • First of all there are a lot of there are a lot of errors in this piece of code. The main problem is that `${request.delay.ms}` is never resolved to real value but is always resolved to value `"${request.delay.ms}"` as `String` and exceptions are raised because `"${request.delay.ms}"` cannot be converted to `long` and if he changes `requestDelay` to `String` no exception is raised because `"${request.delay.ms}"` can be converted to `String` and the value of `requestDelay` will be `"${request.delay.ms}"` – Nikolay Rusev Oct 29 '15 at 15:11
  • that doesn't help. Neither replacing it with `request_delay_ms` – Leo Oct 30 '15 at 03:55
  • i tested it on my own and worked fine...can you please provide us small spring or spring boot project... – Nikolay Rusev Oct 30 '15 at 07:58