samedi 20 mars 2021

Spring not interpolating @Value correctly in test

I have this on my test class:

@TestPropertySource(properties = {
        "spring.profiles.active=test",
})

with an adjacent application-test.yml file with the following contents: This is under the /resources directory

batch.max_records=100
batch.max_wait_seconds=10

I get the following error:

Caused by: java.lang.NumberFormatException: For input string: "${batch.max_records}"

Why is this? I fix it by adding a static initializer block, but want to isolate within a profile.

Update:

I had named the profile with a .yml extension instead of properties. Swapping the extensions fixed it

Aucun commentaire:

Enregistrer un commentaire